<HTML> <TITLE>Random messages</TITLE> <SCRIPT LANGUAGE="javascript"> <!--- HIDE SCRIPT function randomMessage() { return Math.round(Math.random()*9); } //The function randomMessage() uses the built in Math object to produce a random number between 0 and 1 //This is then multiplied by 9, in this case, to get a number between 0 and 9, or ten random messages var message = new Array(); //Defines a new array message[0] = "Welcome, cool and bodacious dude!" //NOTE the square brackets message[1] = "Get lost Smeghead!" message[2] = "Read MacUser every fortnight!" message[3] = "Real men use JavaScript" message[4] = "No-one get out of here alive!" message[5] = "Mac is a way of life" message[6] = "Random is as random does." message[7] = "Beware of the Cyberdog!" message[8] = "All this randomizing is making me dizzy" message[9] = "Java - who needs it!" <!-- END HIDE --> </SCRIPT> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <HR> <FONT SIZE="5" COLOR="#FF0000"> <SCRIPT LANGUAGE="javascript"> document.write(message[randomMessage()]); //writes the random message </SCRIPT> </FONT> <HR> <FONT SIZE="3" COLOR="#FF0000"> Click <A HREF="random.html"> here</A> to reload this page for another message </FONT> </BODY> </HTML>

return to example