Question
Guess game var max = 1000; var guess = Math.floor(Math.random() * max) * 1; label = document.getElementById(output); function tryGuess() { usrAnswer = Number(document.getElementById(guess).value); if (usrAnswer
var max = 1000;
var guess = Math.floor(Math.random() * max) * 1;
label = document.getElementById("output");
function tryGuess() {
usrAnswer = Number(document.getElementById("guess").value);
if (usrAnswer < 0 || usrAnswer > 1000) {
alert("Insert a number between 1 and 1000");
return;
} else {
if (guess != usrAnswer) {
if (guess < usrAnswer) {
label.innerHTML = "
Too high, try again
";
} else if (guess > usrAnswer) {
label.innerHTML = "
Too low, try again
";
}
} else {
label.innerHTML = "
Congratulations! You guessed the number!";
guess = Math.floor(Math.random() * max) * 1;
}
document.getElementById("guess").value = "";
}
}
Modify the program to count the number of guesses the player makes. If the number is 10 or fewer, display Either you know the secret or you got lucky! If the player guesses the number in 10 tries, display Ahah! You know the secret! If the player makes more than 10 guesses, display You should be able to do better!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started