For example, consider the following HTML document.
Cut-and-paste this HTML code into a document called hello.html. Then, load the page into the browser to execute the code and display the message 20 times. Note: to load a page that is stored as a local document on your computer, select "Open Page" from the File menu in the browser.
Write the HTML code for such a page and save it in the document psychic.html. Load the page to execute your code and verify that it does indeed display a different "lucky" number every time. Feel free to elaborate.
An important step in building abstractions for problem solving is library use. Useful routines can be encapsulated in a library file and then loaded whenever they are needed. The use of libraries simplifies programming and allows you to think at a higher level of abstraction.
Add the above element to your psychic.html page and modify the code to make use of the randomInt function defined there. Again, this element should be placed in the HEAD section, below the TITLE.
Note: it is assumed that library files are stored in the same directory as the page being loaded. This means that you will have to make a local copy of the random.js library to be stored along with your HTML documents. You can click on this link to view the contents of random.js, then cut-and-paste the code into a document (named random.js) in your home directory.
For example, the following HTML document contains the definition of the diceRoll function, which uses the randomInt function from random.js.
Wasn't that exciting ?
Cut-and-paste this HTML code into a document called craps.html. Then, load the page into the browser to execute the code and verify that it does produce random rolls of the dice.
A more interesting application involving dice is the casino game craps. Craps is a relatively easy game to understand:
Using pseudo-code, the algorithm for playing the game of craps can be described as follows: