Very simple, yet cool javascript code. In case any one is interested I will breifly explain what is happining in the code. I gave you reputation for this useful code to the community!
1. First it makes a variable called "Quotation" and make it an array (an array is basically a variable that holds several variables.
2. Now it sets the different variables inside the array. Quotation[1] is the first variable inside the Quotation array, so you just increase the number to add another variable (which we are setting to contain quotes), so you could have 50 quotes if you wanted to!
Now the part that is a bit more complicated:
Quote:
|
var Q = Quotation.length;
|
3. This makes a new variable "Q" to be the number of variables in the array, in this case it would be 10.
Quote:
var whichQuotation=Math.round(Math.random()*
(Q-1));
|
4. This makes a new variable "whichQuotation". It uses the random command that is a part of the math functaions to, in simple words, randomly pick which variable, or quote, in the array to choose.
Quote:
function showQuotation(){document.write(Quotation
[whichQuotation]);}
showQuotation();
|
This makes a function "showQuotation". A function is basically a new command that once executed completes the commands inside of it, it is very helpful when doing the same operation multiple times. The function uses document.write to display the variable Quotation[whichQuotation]. Now whichQuotation is a variable that was set as a random number of one of the variable inside the array's numbers, therefore it actually shows on of the quotes (i.e. Quotation[3] could be the randomly picked on, so whichQuotation contains the number 3, so the 3 is put in its place and the variable is now Quotation[3], which is the third variable in the Quotation array. So the script would show the text "Honesty blurts where deception
sneezes.".)
If this was confusing to you, don't worry. Just copy and paste that to the spot in your website you want a random quote, then change the quotes to ones you want, or even things that aren't quotes, and it will work fine. You can change the number of quoates as well, by just adding in a new variables that goes up one, so if you wanted 1 extra quote the ones already there you would just add this after the end of the 10th quote:
Quotation[11] = "Your quote here";