I cannot for the life of me figure out how to close the prompt altogether upon pressing cancel in my code for a guessing game. I’ve tried several things, but each time either the code ignores what I’m trying to do, or ends in an error. Here’s the code in question:
let numGuess = prompt (`Guess the number I am thinking of (between 1 and 10):`);
let num = (4);
let numTries = 1
console.log(numGuess);
numGuess = parseInt(numGuess)
if (prompt == null) {
alert (`Press F5 to play again.`)
}
if (numGuess === num) {
alert (`Correct! You guessed the number in 1 try! Press F5 to play again.`);
}
else while ((numGuess !== num) && (numTries <3))
{
numTries = numTries++
alert (`Incorrect guess. Try again.`)
}