This will be a guessing game for the user. The user will only get 8 guesses to t
ID: 3624794 • Letter: T
Question
This will be a guessing game for the user. The user will only get 8 guesses to try and get the word.
Requirements:
1. Choose a secret word that you want the user to guess
2. Prompt the user for a guess
3. Each time they guess wrong
a. display their guess, tell them it’s wrong, and a display how many guesses they have left
b. prompt them for another guess
c. if they guess correctly, congratulate them
d. if they guess 8 times and they have not guessed correctly, the game is over
This has to be accomplished using while or for loops.
SO FAR I GOT THIS CODE DOWN:
var secret = "record"
var guess
var count = 8
while ( count > 0 && guess != secret)
{
guess = prompt("What's your guess?")
if( guess != secret)
{
count--
document.write("Sorry it's not ", guess ,", you have ", count ," guesses remaining.</br>")
}
else
{
document.write("Congratulations you won! The word is ", secret)
}
}
IT DOES ALMOST EVERYTHING. WHAT I CANT FIGURE OUT IS HOW TO MAKE IT DISPLAY A GAMEOVER MESSAGE WHEN THEY RUN OUT OF GUESSES AND ALSO TELL THEM WHAT THE WORD WAS. ALSO AT THE END THERE IS ALWAYS A PLUS SIGN THAT APPEARS, ANYONE KNOW WHY?
THANK YOU FOR YOUR HELP.
Explanation / Answer
var secret = "record"
var guess
var count = 8
while ( count > 0 && guess != secret)
{
guess = prompt("What's your guess?")
if( guess != secret)
{
count--
document.write("Sorry it's not ", guess ,", you have ", count ," guesses remaining.</br>")
}
else
{
document.write("Congratulations you won! The word is ", secret)
}
}
if(!count)
document.write("Sorry Game is Over !, and The word is ", secret)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.