topical media & game development

talk show tell print

basic-javascript-09-ch09-q1.htm / htm



  <html>
  <head>
  <script language=JavaScript>
  
  var imagesSelected = new Array(false,false,false);
  var noOfImages = 3;
  var totalImagesSelected = 0;
  
  function window_onload() 
  {
     setInterval("switchImage()",4000);
  }
  
  function switchImage() 
  {
  
     var imageIndex;
  
     if (totalImagesSelected == noOfImages)
     {
        for (imageIndex = 0; imageIndex < noOfImages; imageIndex++)
        {
           imagesSelected[imageIndex] = false;
        }
  
        totalImagesSelected = 0;
     }
  
  var selectedImage = Math.floor(Math.random() * noOfImages) + 1;
  while (imagesSelected[selectedImage - 1] == true)
  {
        selectedImage = Math.floor(Math.random() * noOfImages) + 1;
     }
     totalImagesSelected++;
     imagesSelected[selectedImage - 1] = true;
     document.imgAdvert.src = "AdvertImage" + selectedImage + ".jpg";
  
  }
  
  </script>
  </head>
  <body onload="window_onload()">
  <img src="AdvertImage1.jpg" name="imgAdvert">
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.