Rock Paper Scissors issue

Hi, my code was working fine until I went to test the game and now this error message comes up
Output:
/home/ccuser/workspace/javascript_101_Unit_3_v2/rockPaperScissors.js:2
userInput = userInput.toLowerCase();

My code:

const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (
userInput === “rock” ||
userInput === “paper” ||
userInput === “scissors”
) {
return userInput;
} else {
console.log(“Error, the 3 options are rock, paper or scissors.”);
}
};

const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return “rock”;
break;
case 1:
return “paper”;
break;
case 2:
return “scissors”;
break;
}
}

function determineWinner(userChoice, computerChoice) {
if (userChoice === computerChoice) {
return “Game was a tie!”;
}
if (userChoice === “rock”) {
if (computerChoice === “paper”) {
return “Computer has won!”;
} else {
return “User has won!”;
}
}
if (userChoice === “paper”) {
if (computerChoice === “scissors”) {
return “Computer has won!”;
} else {
return “User has won!”;
}
}
if (userChoice === “scissors”) {
if (computerChoice === “rock”) {
return “Computer has won!”;
} else {
return “User has won!”;
}
}
}

function playGame() {
const userChoice = getUserChoice();
const computerChoice = getComputerChoice();
console.log("You threw " + userChoice);
console.log("The computer threw " + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}

playGame();

hi tera1237986385 welcome to the forms first can you please format your code.
here is what it looks like console.log("this. hope this helps")

2 Likes

The getUserChoice function has an argument:

but you did not provide an argument when you called getUserChoice inside the playGame function.

You could do something like
getUserChoice("rock");
or
getUserChoice("scissors");
to fix that.

And, as @riynk33tocodex100 said, please format the code by using the </> button and then pasting the code between the ``` and ``` (and have that last ``` on another line)
so that the code keeps its formatting
to make the code easier to read.

2 Likes