I was asked about creating a javascript that would place an image on a page based on the day of the week. Easy enough right? Well, it took some tinkering, but here it is. For this demonstration I created eight images, each with the number 0 - 7.
However, since the javascript Date Object returns 0 - 6, you will never see the 7. The code for this is relatively simple, as you can see if you look at the source for this file. In the head I've preloaded the image, which, from what I can tell is necessary. Second I've got all of the files I want and named them the same, with the exception of the digit indicating the Day of the Week. Hence the DOW (stands for Day Of Week) for the name followed by a digit followed by .jpg. This is so I don't have to write out 8 (or 31 if you were ambitious enough to do this for each Day Of the Month) individual lines (actually it would be more like 16 lines). It also makes the code to replace the image much easier and shorter to write as well.
So without further ado, this is the day of the week. Remember, according to JavaScript, Sunday is day 0, Monday is day 1, etc.
If you wanted to get the day of the week, counting Sunday as day 1, Monday as day 2, etc, you would simply add 1 to the equation and come up with (and in this case, the number 7 will show up, if you happen to visit this page on Saturday)
One more thing to note is that the JavaScript that changes the image needs to come AFTER the image in HTML code. If not, it doesn't know about the image and can't replace it. The other option would be to put the code in the head of the HTML file and trigger it with a function call.