Assignment 34: A Possible Answer

....describes my mood today.


     You'll need to create three variables that are equal to these three pictures. Then you can enter those variable names into document.write statements all day long. Below are two possible answers. One is what we expect you to do. The second is a little more compact and a little more clever. Try picking it apart yourself.

Possible Answer 1 of 2


<body bgcolor="white" >

<center>

<h1>My Home Page</h1>

<script language="JavaScript">

   var1="pic1.gif"

   var2="pic2.gif";

   var3="pic3.gif"

   now=new Date()

   num=(now.getSeconds() )%3

   num=num+1



   document.write("Random Number: " + num + "<br>")

   if (num == 1)

       {cliche=var1} 

   if (num == 2)

       {cliche=var2}

   if (num == 3)

       {cliche=var3}

  document.write("<img src=" +cliche + ">")

</script>

<p>....describes my mood today.

</center>

</body>

</html>

Or if you are REALLY clever...





<script language="JavaScript">

   var1="pic1.gif"

   var2="pic2.gif";

   var3="pic3.gif"

   now=new Date()

   num=(now.getSeconds() )%3

   num=num+1


   document.write("Random Number: " + num + "<br>")

   document.write("<img src=" + eval("var"+num) + ">")

</script>

<p>....describes my mood today.

</center>

</body>

</html>

 

Did You Get It?

 

Back to the Index Page