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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education