November 5th, 2006
JavaScript Random Number Guessing Game
Here is a step-by-step tutorial on making a guessing game in JavaScript - like this page:
- Create a form. The form should have an input field and a button. When the user clicks the button, an event handler should be used (maybe onclick?) to find out what number the user entered in the form. The form should not go to another page for its action.
- In the head tag, insert JavaScript for the following to first generate a random number (Try to use Math.round(Math.random() * 100)). Save that number in a variable. Then create a function to test what the user entered in the form (document.form.formInputName.value) - against the random number that you set in a variable.

- Now, you may see the clearTimeout() and continueGame() function and wonder what the heck is going on. Take a looksie:

- That will have an alert box come up every 10 seconds asking the user if they wish to continue.
Filed under: JavaScript



Leave a Reply