Can anyone see why I’m throwing undefined in the console here?
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”;
break;
case 1:
return “paper”;
break;
case 2:
return “scissors”;
break;
}
};
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return “This game is a tie!”;
}
if (userChoice === “rock”) {
if (computerChoice === “scissors”) {
return “You won!”;
} else {
return “The computer won!”;
}
}
if (userChoice === “paper”) {
if (computerChoice === “rock”) {
return “You won!”;
} else {
return “The computer won!”;
}
}
if (userChoice === “scissors”) {
if (computerChoice === “paper”) {
return “You won!”;
} else {
return “The computer won!”;
}
}
};
const playGame = () => {
const userChoice = getUserChoice(“rock”);
const computerChoice = getComputerChoice(“”);
console.log(You threw: ${userChoice}
);
console.log("The computer threw: " + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
};
console.log(playGame());