topical media & game development

talk show tell print

basic-javascript-appendix-9-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.