Rock Paper Scissors Game

How am I doing the rock, paper, scissors game wrong?

Here is my code:

const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’)
return userInput
else {
console.log (‘This is an incorrect selection’)
}
}
const getComputerChoice = () => {
const randomNumber = (Math.floor(Math.random () * 3));
switch (randomNumber) {
case 0:
console.log(‘rock’)
break;
case 1:
console.log(‘paper’)
break;
case 2:
console.log(‘scissors’)
break;
}
}

const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return ‘This game was a tie’ ;
}
if (userChoice === ‘rock’) {
if (computerChoice === ‘paper’) {
return “Sorry, the computer has won!”;
} else {
return “You have won this round!”;
}
}
if (userChoice === ‘paper’) {
if (computerChoice === ‘scissors’) {
return “sorry, the computer has won”;
} else {
return “Congratulations, you have won”
}
}
if (userChoice === ‘scissors’) {
if (computerChoice === ‘rock’) {
return “Sorry, the computer has won!”
} else {
return “Congratulations, you have won”;
}
}
};

const playGame = () => {
const userChoice = getUserChoice(‘rock’);
const computerChoice = getComputerChoice();
console.log('You used: ’ + userChoice);
console.log('The computer used: ’ + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
};

playGame();

Hi,
please format your code as described to this guide to make it easier for others to read your code and spot errors.
Can you describe how the result deviated from your expectations?
Do you get an error message?

This function returns ‘undefined’ because you don’t actively return anything. When you call it here:

computerChoice is undefined.
It is very helpful to log the variables to the console in order to see if they store a value you expect and to see the where the error is caused.

I don’t know if this makes any difference but you are told to use return in the getComputerChoice function. This is how I did it:

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