Hope you're all doing well ! I'm newbie with js and I've written the code below but it doesn't work the way I expected it to do. Need help ! The thing is, I want the loop to continue until "numberToGuess = guessNumber" but unfortunately, it breaks at second loop; even if numberToGuess is not equal to guessNumber. Can Someone explain me how to fix that please ? Thx!
const numberToGuess = Math.round(10*Math.random());
let guessNumber;
while(numberToGuess !== guessNumber){
guessNumber = prompt("Guess the hidden number: ");
if(guessNumber < numberToGuess){
console.log("Too low");
}else if(guessNumber > numberToGuess){
console.log("Too high");
}
}
console.log("Congrats ! You found it !");
console.log("Number to guess = " + numberToGuess + "\nGuessed number = " + guessNumber);