Greetings, not sure where my undefined is coming from? I need extra eyes please? I am Coded’out!
const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (
userInput === "rock" ||
userInput === "paper" ||
userInput === "scissors" ||
userInput === "bomb"
) {
return userInput;
} else {
console.log("Error!");
}
};
const getComputerChoice = () => {
let random = Math.floor(Math.random() * 3);
switch (random) {
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 "Tie";
}
if (userChoice === "rock") {
if (computerChoice === "paper") {
return "Computer won!";
} else {
return "You won!";
}
}
if (userChoice === "paper") {
if (computerChoice === "scissors") {
return "Computer won!";
} else {
return "You won!";
}
}
if (userChoice === "scissors") {
if (computerChoice === "rock") {
return "Computer won!";
} else {
return "You won!";
}
}
if (userChoice === "bomb") {
return "Nuked, you win!";
}
};
const playGame = () => {
let userChoice = getUserChoice("paper");
let computerChoice = getComputerChoice();
console.log(
`You played: ${userChoice} and the computer played: ${computerChoice} `
);
// console.log(`The computer threw: ${computerChoice}`);
console.log(determineWinner(userChoice, computerChoice));
};
playGame();