Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

How to Setup a Randomising Function

By Arbitrary Constant
2007-11-17


Defining your entities

In this case, we wish to generate a random quote, so we need to define a long list of quotes from which a script can pick one out. To do this, we define an array. An array is basically a one-dimensional matrix that contains every possible piece of information in it you would like displayed. It is from the array that the randomising function will pick the random (in this case) quote.
The script utilised in the example in the right column uses the following array:
quotes = new Array
(
"This is quote 1",
"This is quote 2",
"This is quote 3",
...
"This is the last quote"
);
It is that simple. Of course, there are many ways to create an array, but in this case, this was the easiest way of finding a solution to the given requirements. The only thing to note is that the array is named "quotes" and that the last quote does not have a comma before the close parenthesis. If it did have a comma, the script wouldn't work.


Tutorial Pages:
» How to set up a randomising function
» Defining your entities
» Defining a randomising function
» Displaying the random entity


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» Introduction to JavaScript Tutorial

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources