Rock Paper Scissors_returning undefined

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-functions/projects/rock-paper-scissors-javascript

I am getting undefined for the last two options. It works for a tie or if userChoice is rock. Can’t find the issue.

const getUserChoice = userInput=>{
userInput = userInput.toLowerCase();
if (userInput===‘rock’|| userInput===‘paper’|| userInput===‘scissors’){
return userInput;
} else{
console.log(‘Error!’);
}
}
const getComputerChoice=()=>{
const randomNumber=Math.floor(Math.random ()*3);
switch(randomNumber){
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissors’;
}
};
const determineWinner=(userChoice, computerChoice)=>{
if(userChoice===computerChoice){
return’Game is a tie.’;
}
if (userChoice===‘rock’){
if(computerChoice===‘paper’){
return ‘Computer won!’;
}else{
return ‘Congratulations, you won!’;
}
if (userChoice===‘paper’){
if(computerChoice===‘scissors’){
return ‘Computer won!’;
}else{
return ‘Congratulations, you won!’;
}
if (userChoice===‘scissors’){
if(computerChoice===‘rock’){
return ‘Computer won!’;
}else{
return ‘Congratulations, you won!’;
}
}
}
}
};
console.log(determineWinner(‘rock’,‘paper’));
console.log(determineWinner(‘paper’,‘paper’));
console.log(determineWinner(‘paper’,‘scissors’))

Hi Giga1918638374,

your issue is in a missing curly brace after each ‘if’ statement in the function
‘determineWinner’ starting with the second one.
Well, technically they are not missing since they are all at the end but it breaks the logic of it.

It should be like this:

To avoid this in the future I would recommend to use indentation - it shows clearly and graphically what’s inside what.

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.