The Upper Limit
The Tipster... Tip-O-Rama...
Once again we're dealing with a random number script or set of scripts (it's actually two). Here again is what the script's output looks like followed by the script itself.
And here's what it all looks like:
|
function RandomNumber(upper_limit) |
Notice it follows the traditional function format except that the instance, those two parentheses, now have something written in them. That's new, huh? That's saying that the author wants this function to operate on that variable alone. By stating that, the author can give that variable a value later. In the case of this script, it's a hard number written right into the code, but if you want you can set the variable to be filled in by a prompt. The prompt would pop up, ask the viewer which number should be the upper limit, and that number would be set as the "upper_limit" variable. Make sense?
Okay, so where do we get the upper limit? It comes in the second script in this line:
var upper_limit = 50; |
You could have probably guessed that, though. See how it's set as a variable?
So, look at what is happening: You create a function that will manipulate numbers to get a random number somewhere between one and "something" by using a variable called "upper_limit." That's all loaded into the memory. Then the second script is enacted and the variable "upper_limit" is given a value. The function runs and a number is produced. It's actually a pretty clever and compact way of doing things.
The question now is... how do those numbers and letters get to the page? It is a mystery that will have to wait until next week.
Next Time: document.write
More for Developers
On the Codeguru Forums
Visit the Forums »Featured Partner Resources
Get your Android Apps ready for Intel® Atom™ processor-based smartphones and tablets now.
Use the Android NDK to deliver the best performance on Intel® Atom™ processor-based devices.
The Android community on the Intel® Software Network has everything you need to prepare your apps for Intel® Atom™ processor-based devices.



Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.