// This function returns a random number for the variable num, which is specified when you use the function.
// You type rand(x) to use the function, where X is the number of iterations, as you will see later.
// (These comments are for your educational purposes and you can change them as you see fit.)
function rand(num)
{
return (Math.floor(Math.random() *num));
}
// Math.random() gives you a random number between 0 and 1, so you multiply it by the variable num to get something close to the iteration you want.
// Math.floor then rounds that number down, no matter what it is. It could be 24.999999, it would still become 24.
// And return simply returns the result to the Javascript interpretor.
// I used to use the following code to write a random quotation to the screen.
// You can change the array name (quip in this case) to whatever you like, hopefully something more descriptive like randomImage, randImg, or even img... or broccoliAndLimaBeans, if you like.
// I removed the quotations, but you should replace what I put in with the path to your image.
// (Yeah, I only had 4 quotations... sad, huh? ^_^)
var quip = new Array(3);
quip[0] = "Formerly quotation 1";
quip[1] = "Formerly quotation 2";
quip[2] = "Formerly quotation 3";
quip[3] = "Formerly quotation 4";
// This code will randomly store the value of the ith entry of the array quip into a string called quote.
// Again, you can change the variable names (quip, quote, rand, etc.).
quip.length++;
var i = quip.length -1;
var quote = quip[rand(i)];
// Finally, this will put your image in place.
// Be sure to watch those quotation marks... if you open with single hashes, close with them. If you use double hashes, close with them. If your code contains double hashes, use single hashes to contain it, and vice versa.
// If you need to use a single hash and a double has, you can do it the long way ('HTML' + "'" + 'more HTML') or the short way (\' or \").
document.write('<img src="' + quote + '" />');