Home : Internet : JavaScript : Image of the Day

How to Display a Different Image Each Day

Use the code below to display a different image on your web page for each day of the week (as per the example on the right).

In this example the images are stored in a folder called "images". Change the imlocation variable to reflect the location of your own images.

<script language="JavaScript"><!--
var imlocation = "images/";
 function ImageArray (n) {
   this.length = n;
   for (var i =1; i <= n; i++) {
     this[i] = ' '
   }
 }
image = new ImageArray(7)
image[0] = 'sunday.gif'
image[1] = 'monday.gif'
image[2] = 'tuesday.gif'
image[3] = 'wednesday.gif'
image[4] = 'thursday.gif'
image[5] = 'friday.gif'
image[6] = 'saturday.gif'
var currentdate = new Date();
var imagenumber = currentdate.getDay();
document.write('<img src="' + imlocation + image[imagenumber] + '">');
//--></script>