Rock , paper , scissors project

I’m having a problem understanding what went wrong under function determineWinner. When I run it
in both cases shows that computer won, also every other combination works fine. Problem seems to be with rock and paper combinations…

const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === ‘rock’ || userInput=== ‘paper’ || userInput === ‘scissors’) {
return userInput;
} else {
console.log(‘Error’);
}
};

//console.log(getUserChoice(‘rock’));

const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3);
if (randomNumber === 0) {
return ‘rock’;
} else if (randomNumber === 1) {
return ‘paper’;
} else if (randomNumber === 2) {
return ‘scissors’;
} else {
console.log(‘error!’);
}
};

const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return ‘game was a 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!’;
}
}
};

console.log(determineWinner(‘rock’, ‘paper’));
console.log(determineWinner(‘paper’, ‘rock’));

1 Like

Just here your second if statement doesn’t have the conditional equality operator (either (==) or (===)) and as such is not working as intended!

2 Likes

Yeah I was looking at that line of code for past 20min and didn’t see it … Thank you so much !

1 Like