My Home Page

....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 if 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 type="text/javascript">
   var1="pic1.gif"
   var2="pic2.gif";
   var3="pic3.gif"
   now=new Date()
   num=(now.getSeconds() )%3
   num=num+1
   quot="'"   //this is double quote, single quote, 
   double quote which produces '
   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=" + quot + cliche + quot +">")
</script>
<p>....describes my mood today.
</center>
</body>
</html>

Or if You are REALLY Clever


<h1>My Home Page</h1>
<SCRIPT type="text/javascript">
   var1="pic1.gif"
   var2="pic2.gif";
   var3="pic3.gif"
   now=new Date()
   num=(now.getSeconds() )%3
   num=num+1
   quot="'"   //this is double quote, single quote, 
   double quote which produces '
   document.write("Random Number: " + num + "<br>")
   document.write
   ("<img src=" + quot + eval("var"+num) + quot +">")
</script>
<p>....describes my mood today.
</center>
</body>
</html>

Close this window to return to JavaScript Primer #23