Hello,
I’m working on the Rock, Paper, Scissors functions project for JS, and I cannot seem to solve this bug. The return always shows usersChoice as Rock, regardless of what I input in the playGame function. I think the issue must be in my getUserChoice function, just not sure what the error is.
Any help would be greatly appreciated, full code below.
const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb') {
return userInput;
} else{
return console.log("Please use a correct input such as rock, paper, or scissors.");
}
};
const getComputerChoice = (computerInput) => {
computerInput = Math.floor(Math.random() * 3) + 1;
if (computerInput === 1){
return 'rock';
}
if (computerInput === 2){
return 'paper';
}
if (computerInput === 3){
return 'scissors';
}
return computerInput;
};
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice){
return console.log('This round is a tie.');
}
if (userChoice === 'rock'){
if (computerChoice === 'paper'){
return console.log('You lose. The computer wins');
}
if (computerChoice === 'scissors'){
return console.log('You win!!!');
}
}
if (userChoice === 'paper'){
if (computerChoice === 'scissors'){
return console.log('You lose. The computer wins');
}
if (computerChoice === 'rock'){
return console.log('You win!!!');
}
}
if (userChoice === 'scissors'){
if (computerChoice === 'rock'){
return console.log('You lose. The computer wins');
}
if (computerChoice === 'paper'){
return console.log('You win!!!');
}
}
if (userChoice === 'bomb'){
return console.log('You just dropped a bomb... and won!!!')
}
};
const playGame = () => {
const userChoice = getUserChoice('not rock');
console.log('User chose: '+ userChoice);
const computerChoice = getComputerChoice();
console.log('Computer chose: ' + computerChoice);
determineWinner(userChoice, computerChoice)
};
playGame();