dcsimg

Assignment 49: A Possible Answer

This...

<SCRIPT LANGUAGE="JavaScript">

var newurls=new Array()
newurls[0]="http://www.cnn.com"
newurls[1]="https://www.htmlgoodies.com"
newurls[2]="http://www.yahoo.com"

var Images=new Array()
Images[0]="cnn.gif"
Images[1]="goodies.gif"
Images[2]="yahoo.gif"

now=new Date()
num=(now.getSeconds())%3

var adrs = newurls[num]
var pic = Images[num]

document.write("<A HREF=" + adrs + "><IMG SRC=" + pic +" BORDER=0></A>")

</SCRIPT>

 

Gives you this...

 

     In order to get the effect, you need to set up two arrays. One will contain the images and the other the URLs. Make sure the Images and the URLs are in the same order. Then you can go random with one and the other will follow as long as you call for the number using the same variable name. Get it? If 2 is the random number, two must be called for in both arrays if it is to line up correctly. Notice I also added the BORDER="0" so that the blue border around the image was taken away.

 

Did You Get It?

 

Back to the Index Page