Challenge: Guess The Number
Write a simple program using JavaScript that:
- Generates a random integer between 1 and 20
- Prompts the user to guess the number and
- If the guess is correct, congratulate the user and end the game
- If the guess is too low or too high, tell the user so and let them guess again
- After 5 guesses, or the user guesses correctly, tell the user if they won or lost
Use prompt() and alert() for user interaction.
Hints
- How do you generate a random number? How about a random integer?
- How do you convert string input to an integer?
- How could you prompt the user over and over?
Example Solution