+ 1
Can anyone debug this Iām stuck
If the number is guessed it still prints the else clause var correctGuess = false; var correctGuess_2 = false; var randomNumber = Math.floor(Math.random() * 6 ) + 1; var guess = prompt('I am thinking of a number between 1 and 6. What is it?'); if (parseInt(guess) === randomNumber ) { correctGuess = true; } if (correctGuess===true) { document.write('<p> You guessed the number!</p>') } if(correctGuess===false){ alert("That was incorrect try again") var guess2 = prompt("Second guess attempt"); } if(parseInt(guess2)===randomNumber) { correctGuess_2 = true; } if (correctGuess_2 === true) { document.write('<p>You got it that time!</p>'); } else { document.write('<p>Sorry. The number was ' + randomNumber + '</p>') }
1 Answer
+ 1
you didn't create an else that makes correctGuess false if your guess is not correct
https://code.sololearn.com/W9jz5zjXx7BC/?ref=app