A Random URL

This assignment is pretty close to a re-hash of the example in Primer 26, except you needed to denote the array of URL's using the newurls[0] format. Once you grabbed a handle on that part - it ran just the same. However, the output was pointed at top.location.href. But we gave you that too. Here's the code:

The Source

<html>
<head>
<SCRIPT type="text/javascript">
     newurls=new Array()
     newurls[0]="http://www.cnn.com"
     newurls[1]="http://www.ibm.com"
     newurls[2]="http://www.digital.com"
     newurls[3]="http://www.disney.com"

 function picksite()
   {
     now=new Date()
     num=(now.getSeconds())%4
     top.location.href = newurls[num]
   }
 </script>    
</head>
<body>
<center>
    <h2>A Random URL</h2>
    <form>
        <input type="button" 
	value="Click to go to a Random Site" 
	onClick="picksite()">
    </form>
 </center>
</body>
</html>

Close this window to return to Primer #26