Skip to content
Advertisement

JavaScript Rock Paper Scissors – User input won’t display in console

I’m trying to make a RPS game to play in the console. This is what I have so far. At the moment it is only console logging “Do you choose rock, paper or scissors?” and “Error! Try again!”). In other words it is not checking if the user is actually entering ‘rock, paper or scissors.’ What am I doing wrong?

const userInput = console.log("Do you choose rock, paper or scissors?"); 
    if(userInput ==="paper" || userInput ==="rock" || userInput ==="scissors"){
        console.log("Your choice is " + `${userInput}`);
    } else {
        console.log("Error! Try again!");
    }

Advertisement

Answer

Just change const userInput = console.log("Do you choose rock, paper or scissors?"); to const userInput = prompt("Do you choose rock, paper or scissors?");

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement