Goodevening, it’s my first time posting on a forum on the internet, I apologize for my clumsiness. I wanted to ask help for a this exercise, I pretty much followed the hints the exercise gave me, but when I get to step 11 to test the “determineWinner” function, i get triple outputs as “The computer won” plus “undefined”. Can anyone give it a look and tell me what’s wrong?
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
return userInput;
} else {
console.log('Error!')
}
};
const getComputerChoice = computerChoice => {
let randomNumber = Math.floor(Math.random() * 3)
switch (randomNumber) {
case 0:
return 'rock';
break;
case 1:
return 'paper';
break;
case 2:
return 'scissors';
break;
default:
return 'Error!';
break;
}
};
function determineWinner(userChoice, computerChoice) {
if (userChoice === computerChoice) {
console.log('The game was a tie!');
}
};
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
console.log('The computer won!');
} else {
console.log('You won!');
}
}
if (userChoice === 'paper') {
if (computerChoice === 'scissors') {
console.log('The computer won!');
} else {
console.log('You won!');
}
}
if (userChoice === 'scissors') {
if (computerChoice ==='rock') {
console.log('The computer won!');
} else {
console.log('You won!');
}
};
console.log(determineWinner('rock', 'paper'));