Departments
 Info
   Home Page
   Articles
   Software Goodies

 Explanations
   How do they do that?
   The Web in Focus

 Resources
   Web Site Stuff
   Tech Books
   E-Books
   Tech Toys
   Web Hosting
   Links

 Women
   Opinion
   Tech Women
   Women's Studies

 Tech News
   Computer Security
   Databases
   Java
   Linux
   MP3
   PC Software
   Robotics
   Site Owner
   Tech Latest
   Web Development
   XML

 Spread the Word
   Newsletter
   Recommend this Page

 Site Info
   Legal Disclaimer
   Privacy
   Contact

 Lighter Side
   Crazy for Life
   crazy for romance
   Crazy for Kitties
   Crazy for Dogs
   Crazy for Cows

Copyright 2000-2001, hertechnology.com

 
How do they do that?
Generating Random Quotes

Quote:

If you refresh this page (in IE use the "refresh" button, in Netscape use the "reload" button") you will get a different quote. This is done (in this situation) by using JavaScript. (It can also be done using other computer languages like Perl.) Let's discuss, in general terms, how this effect was done.

First of all, a collection of quotes was gathered. Second, they were each typed in using a particular format that JavaScript requires. (Computers are picky and you have to follow their rules.) For example, here is one of the quotes:

'"You are never given a wish without
also being given the power to make it true.
You may have to work for it, however." -- Richard Bach';

Note the whole text is surrounded in single quote marks. This separates what we want to make the quote from the rest of the JavaScript.

Now for the tricky part. In many computer programming language, like JavaScript, you can take a collection of things and associate them together as one unit. Think of it as a jewelry box with a lot of little compartments. The jewelry box is one unit, but it has sections in it for different things.

The jewelry box is called an "array" in JavaScript. We put one quote in each of the array's compartments. The next example shows putting the first three quotes in. The compartments are distinguished from each other by using different numbers, as you'll see on the next page.

Page 2

Tech Books

Tech Toys

More News

  Want to bookmark this site? Press Control-D. (Hold down the control key and the letter D at the same time.)