We have all of the returns up and ready for display, but there’s one more test before the user gets the effect. It’s always something ain’t it? Here’s the script and its effect once again:
The purpose of these lines of code is to look at the number and decide what two-letter extension should follow. Let’s think it through logically. Yes, you could set up a condition for every number 1 through 31, but that’s really going overboard.
- There are only three times when the “st” is needed.
- There are only two times when the “nd” is needed.
- There are only two times when the “rd” is needed.
- The rest of the numbers get the “th”.
So we set up the conditions:
You probably already know that the HTML <SUP> makes text appear as the smaller letters up high. You can also set that to <SUB> if you’d like, but I don’t think the effect is quite as nice.
Did you catch that double vertical lines means “or”? That’s a great way of adding multiple conditions that have the same result all in one line of code rather than writing each condition out on its own. If you don’t know, you’ll find that vertical line on the same button as the backslash, usually just above the ENTER key.
As with all If statements, if the first condition does not apply, the script rolls over to the next one in line. It looks like this:
OK, we’ve got all the parts. Now we’ll use a basic document.write() statement to get it onto the page for all the world to see:
document.write("Today is " +day+ " " +Month+ " " +date+ ender+ ", " +Year+ ".")
Next Time: A Random Banner Script