Using JavaScript and html, a do while loop, and let instead of var

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question
Using JavaScript and html, a do while loop, and let instead of var
GUESS THE NUMBER GAME
In this task, you will create a program that plays a guess the number game with the user. Your
program will generate a random secret number by setting a variable equal to
Math.floor(Math.random()*20) + 1
(This expression generates a random number from 1 to 20 and is included in the starter code).
Then, it will allow the user up to five guesses to guess the correct number.
After generating the secret number. Your program should prompt the user: "Guess a number
from 1-20 (secret number)!". The number in the parenthesis should be the actual secret number
(e.g., "Guess a number from 1-20 (14)!").
The program should handle the following cases and allow up to five guesses.
1. If the user enters a number less than 1 or greater than 20, it should generate an alert
instructing them to guess between 1 and 20. Then, if they still have guesses left, it
should prompt them for another guess.
2. If the guess matches the secret number, it should end the game and print, "You win!" in
the <h2></h2> tags with id="outcome".
3. If the guess is smaller than the secret number, it should generate an alert that says, "Too
small!". Then, if they still have guesses left, it should prompt them for another guess.
4. If the guess is larger than the secret number, it should generate an alert that says, "Too
large!". Then, if they still have guesses left, it should prompt them for another guess.
5.
f they have made five failed guesses, it should end the game and print, "You lose!" in
the <h2></h2> tags with id="outcome". Any guess which is not the correct number
counts as a failed guess regardless of whether the guess was in the range 1-20 or not.
In all cases, it should print "The number was " followed by the secret number in the <p></p>
tags with id="answer".
ADDITIONAL CLARIFICATIONS
You can assume the user enters a number in a reasonable form (e.g., using numeric
characters like "6", "-2", or "23"). You do NOT have to handle any kind of word input like
random letters or written numbers (e.g., "six") for this program.
You must use a loop.
●
Transcribed Image Text:GUESS THE NUMBER GAME In this task, you will create a program that plays a guess the number game with the user. Your program will generate a random secret number by setting a variable equal to Math.floor(Math.random()*20) + 1 (This expression generates a random number from 1 to 20 and is included in the starter code). Then, it will allow the user up to five guesses to guess the correct number. After generating the secret number. Your program should prompt the user: "Guess a number from 1-20 (secret number)!". The number in the parenthesis should be the actual secret number (e.g., "Guess a number from 1-20 (14)!"). The program should handle the following cases and allow up to five guesses. 1. If the user enters a number less than 1 or greater than 20, it should generate an alert instructing them to guess between 1 and 20. Then, if they still have guesses left, it should prompt them for another guess. 2. If the guess matches the secret number, it should end the game and print, "You win!" in the <h2></h2> tags with id="outcome". 3. If the guess is smaller than the secret number, it should generate an alert that says, "Too small!". Then, if they still have guesses left, it should prompt them for another guess. 4. If the guess is larger than the secret number, it should generate an alert that says, "Too large!". Then, if they still have guesses left, it should prompt them for another guess. 5. f they have made five failed guesses, it should end the game and print, "You lose!" in the <h2></h2> tags with id="outcome". Any guess which is not the correct number counts as a failed guess regardless of whether the guess was in the range 1-20 or not. In all cases, it should print "The number was " followed by the secret number in the <p></p> tags with id="answer". ADDITIONAL CLARIFICATIONS You can assume the user enters a number in a reasonable form (e.g., using numeric characters like "6", "-2", or "23"). You do NOT have to handle any kind of word input like random letters or written numbers (e.g., "six") for this program. You must use a loop. ●
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Matrix multiplication
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr