I am a Javascript beginner.
I am working on a simple "Guess the number" game which is played in the console. It works fine on Firefox but for some reason, it doesn't on Chrome.
Can anyone point me in the right direction?
EDIT: My specific issue is I can load the page on Firefox and play the game. There's a prompt asking for a number, then a message in the console informs the user if the number is correct, too high or too low.
When I load the page on Chrome, there is a prompt but no matter what I enter, no message shows up in the console.
function getRandomNum() {
return Math.floor(Math.random() * 101);
}
let randomNum = getRandomNum();
let userNum = 0;
let guesses = 15;
function guessNum(randomNum, userNum) {
while (guesses > 0) {
userNum = parseInt(prompt("Guess the number between 1 and 100:", ""), 10);
if (userNum > randomNum) {
guesses--;
let result = "Too high! Try again";
result += "\n";
result += `You have ${guesses} tries left`
console.log(result);
} else if (userNum < randomNum) {
guesses--;
let result = "Too low! Try again";
result += "\n";
result += `You have ${guesses} tries left`
console.log(result);
} else if (userNum === randomNum) {
console.log(`Yes, it's ${randomNum}! \nWell done!`);
}
}
if (guesses == 0) {
console.log(`Aw, the answer was ${randomNum}. Better luck next time.`)
}
}
console.log(guessNum(randomNum, userNum));