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’))