As you have seen in lecture, the implementation of rollovers depends on catching some JavaScript events and reacting to them, i.e. on creating Event Handlers. The events we are interested in are Click, MouseOver, and MouseOut. If you need a reminder about the relevant code to implement an image rollover, the lecture notes are linked here.
Math.random() generates a random fractional number
between 0 and 1.
To get a random number between 0 and n (n excluded), you use:
n * Math.random()
If you want an integer between 0 and n (n excluded), you can use
the Math.floor() Javascript function: Math.floor(n
* Math.random())
You may want to look at this page, which uses the formula given above to produce integer random numbers in a certain range. (You will need to reload the page several times in order to see several random numbers.) You are encouraged to look at the source code as well!
Here is how to implement this:
Create a new web page. Use Javascript to: