I cannot get the bomb function of my rock, paper, scissors to work? when I set the user’s choice to bomb (or any choice) it will say it’s a tie, when I remove the ‘bomb’ logic from determineWinner it works fine…
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb') {
return userInput;
} else {
console.log('invalid choice!')
}
};
const getComputerChoice = () => {
switch (Math.floor(Math.random() * 3)) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
};
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === 'bomb') {
return 'You blew your opponent up!'
}
if (userChoice === computerChoice) {
return 'It\'s a tie!';
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'Computer wins!';
} else {
return 'You win!';
}
}
if (userChoice === 'paper') {
if (computerChoice === 'scissors') {
return 'Computer wins!';
} else {
return 'You win!';
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'Computer wins!';
} else {
return 'You win!';
}
}
};
const playGame = () => {
const userChoice = getUserChoice('paper');
const computerChoice = getComputerChoice();
console.log('You played: ' + userChoice);
console.log('The computer played: ' + computerChoice);
console.log(determineWinner());
}
playGame()