I'm a web developer who works with HTML, PHP, CSS, ExpressionEngine, Javascript, jQuery, MySQL, SEO and UI/UX design. Always looking to learn new web related stuff, and a bit of a PC gamer. You can also find me on Twitter and LinkedIn.

Posts Tagged: formatting

Text

Here’s a little javacript function that will get the date ordinal (the bit after the date which can be st, nd, rd or th). It’s by no means perfect, and there’ most likely a more efficient way of doing it, but thought it useful enough to share

function get_date_ordinal(num) {
  var end_num = num.charAt(num.length - 1);
  var start_num = num.charAt(0);
  var abbrev = 'th';
  if (end_num == '1' && start_num != '1') abbrev = 'st';
  if (end_num == '2' && start_num != '1') abbrev = 'nd';
  if (end_num == '3' && start_num != '1') abbrev = 'rd';
  return num + abbrev;
}

I knocked this together as I was pulling in a daily RSS feed, and wanted to present the date in a slightly different way to what was provided.

Text

Indent your code.

Quite simple reasoning to this one, it makes it easier to read. I mean, what would you rather look at when coding? This:

<html>

  <head>

    <title>This is our home page</title>

  </head>

  <body>

    <h1>Hello World!</h1>

    <p>Here's a list of random stuff:</p>

    <ul>

      <li>Alligator</li>

      <li>Radiator</li>

      <li>Flibbetygibbet</li>

    </ul>

  </body>

</html>

Or this:

<html><head><title>This is our home page</title></head><body><h1>
Hello World!</h1><p>Here's a list of random stuff:</p>
<ul><li>Alligator</li><li>Radiator</li><li>Flibbetygibbet</li>
</ul></body></html>