I am in the Rock Paper Scissors challenge

Can someone tell me where the bug is in my code in this exercise? I can’t figure out where I went wrong. It is the Rock Paper Scissors javascript.

If i look at your other functions like getUserChoice and computerChoice, I see you initialize the function correctly:

const getComputerChoice = () => {

yet your determineWinner function:

const determineWinner(userChoice, computerChoice) => {

the assignment (=) is missing

Thanks! :grinning: :grinning: :grinning:

It says there is something else wrong with it as well.

Have you looked at the error? There is generally useful information in the error

Yes it says there is a ; at line 45 but I have tried it with and without and it doesn’t change anything

How did you nest all those conditions? Is that a logic flow? Seems some conditionals are unreachable.

Which ones are unreachable??

if (userChoice === 'paper') for example, given this is nested within the rock check:

 if (userChoice === 'rock') {
      // code
     if (userChoice === 'paper')
}

so userChoice paper will never be true, given you already validated that userChoice is rock

you need to understand this structure, you validate each user choice (after each other)

if user choice is rock {

}
if user choice is paper {

}
if user choice is scissors {

}
then within each `if` condition, you determine with another `if/else` whether the computer or user has won

In JS you may also want to review the If, Else, and Elif statements. There are several ways to get to the solution using these 3 statements. I want to assure you when I first started this task it seemed like there was no winning and today I look back and think wow why was that so hard. For me, the key to JS lies in these 3.

Yay I did it! The only thing I could figure out now is the userInput = userInput.toLowerCase();

Kept giving me an error. Here is my revised code which works (other than the above).

const getUserChoice = (userInput) => {
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
return userInput;
} else {
console.log('Error. Please type 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 'the game is a tie'};
if (userChoice === 'rock') {
if (computerChoice === 'scissors') {
return 'You are the winner!'} else { return'The computer has won!'};
};
if (userChoice === 'scissors') {
if (computerChoice === 'paper') {
return 'You are the winner!'} else { return'The computer has won!'};
};
if (userChoice === 'paper') {
if (computerChoice === 'rock') {
return 'You are the winner!'} else { return'The computer has won!'}
}
};

const playGame = () => {
const userChoice = getUserChoice('paper');
const computerChoice = getComputerChoice();
console.log('You threw:' + userChoice);
console.log('The Computer threw:' + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
};

playGame();

Signature-Rightful-2020 (5 sec frame rate).gif