2

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));
  • What do you mean by *doesn't work*? How does the actual result differ from the expected one? – Konrad Sep 05 '22 at 11:02
  • @KonradLinkowski Sorry, I mean when I open it with Firefox, it prompts the user for a number, then in the console it shows whether or not it's correct. With Chrome, nothing happens in the console. – pseudodejapris Sep 05 '22 at 11:08
  • I get exactley the same result in both Chromium and Firefox, so it looks like your issue is somewhere else. If you could include some more details in your question, with what specificially isn't working, that might help. – Alicia Sykes Sep 05 '22 at 11:25
  • Try this https://stackoverflow.com/questions/18760213/chrome-console-log-console-debug-are-not-working – Cognitronik Sep 05 '22 at 11:56

0 Answers0