Explore BrainMass
Share

Guess a Number - Java Script and HTML

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

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.

© BrainMass Inc. brainmass.com October 17, 2018, 1:27 am ad1c9bdddf
https://brainmass.com/computer-science/random-number-generation/guess-a-number-java-script-and-html-338385

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.

$2.19
Similar Posting

javascript - random number guessing game

I want to make a guessing game. Upon clicking the button on the page, the computer will generate a random number between 0-20. I then should guess the number in the first field.(lets say I have 5 attempts).
The number I guess should be compared with the random generated number. If I guess correctly, the second field could display a message like "you win", else it should display "more" or "less" depending on my guess. If I fail to guess those 5 times, I should lose and the answer should appear in the second field.

View Full Posting Details