So I am having an issue with my code for the rock paper scissors project. When the user chooses ‘scissors’ and the computer chooses anything but scissors, I get an error saying:
/home/ccuser/workspace/javascript_101_Unit_3_v2/rockPaperScissors.js:40
if(userchoice === 'scissors') {
^
I also get this same error when the user chooses ‘bomb’
Here is my code below:
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'scissors' || userInput === 'paper' || userInput === 'bomb') {
return userInput
} else {
console.log('Error, you must choose rock paper or scissors');
}
};
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 'This game is a tie';
}
if(userChoice === 'rock') {
if(computerChoice === 'paper') {
return "Sorry, the computer won!";
} else {
return "Congrats! You won!"
}
}
if(userChoice === 'paper') {
if(computerChoice === 'scissors') {
return "Sorry, the computer won!";
} else {
return "Congrats! You won!";
}
}
if(userchoice === 'scissors') {
if(computerChoice === 'rock') {
return "Sorry, the computer won!";
} else {
return "Congrats, you won!";
}
}
if(userChoice === 'bomb') {
return "Congrats! You won";
}
};
const playGame = () => {
const userChoice = getUserChoice('bomb');
const computerChoice = getComputerChoice();
console.log('You threw: ' + userChoice);
console.log('The computer threw: ' + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
};
playGame();
Any help would be appreciated! Thank you