Explore BrainMass

Guess a Number - Java Script and HTML

Write a HTML script that plays a "guess the number" game as follows.

The program chooses the number to be guessed by selecting a random integer in the range of 1 to 1000. The script displays the prompt "Guess a number between 1 and 1000" next to a text field. The player types a guess into the text field and clicks a button to submit the guess to the script. If the player's guess is incorrect, the program should display "Too high. Try again." or "Too low. Try again." to help the player "zero in" on the correct answer, and should clear the text field so that the user can enter the next guess. When the user enters the correct answer, display "Congratulations. You guessed the number!" and clear the text field so the user can play again.

Solution Summary

This solution includes Java Script code in conjunction with HTML. The Java Script code deals with random number generation. The user guesses a number between 1 and 1000. If the player's guess matches the random number generated by script, an appropriate message is displayed. However, if the user's guess is less than the number generated, then accordingly another message is displayed.