Unable to solve If Userchoice error in the Rock, Paper, and Scissors game

Here is my code thus far:

const getUserChoice = userInput => {

userInput = userInput.toLowerCase();

if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’){

return userInput;

} else {

console.log(‘Error!’);

}

};

function getComputerChoice() {

const randomNumber = Math.floor(Math.random() * 3);

switch (randomNumber) {

case 0:

return 'rock';

case 1:

return 'paper';

case 2:

return 'scissors';

}

};

function determineWinner() {

if (userChoice === ComputerChoice) {

return 'The game was a tie!'

}

if (userChoice === ‘rock’){

if (ComputerChoice === 'paper'){

  return 'The computer won!'

} else {

    return 'The player won!'

  }

}

if (userChoice === ‘paper’){

if (ComputerChoice === 'scissors'){

  return 'The computer won!'

} else {

    return 'The player won!'

}

}

if (userChoice === ‘scissors’){

if (ComputerChoice === 'rock'){

  return 'The computer won!'

} else {

    return 'The player won!'

}

}

}

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

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

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


I seem unable to get rid of this error:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:24
if (userChoice === ComputerChoice) {
^

no matter what I do.

At the moment, I am going line-by-line in the tutorial video to see any differences between the code they write and mine, but it has not helped thus far. I would appreciate some insight. Thank you.

I have figured out what is going on.

So my code:


const determineWinner(userChoice, computerChoice) {
if (userChoice === ComputerChoice) {
return ‘The game was a tie!’
}
if (userChoice === ‘rock’){
if (ComputerChoice === ‘paper’){
return ‘The computer won!’
} else {
return ‘The player won!’
}


was giving me an error because I did not reference userChoice within the parenthesis, in addition to having the first part of ComputerChoice capitalized.

Here is my fixed code:


const getUserChoice = userInput => {

userInput = userInput.toLowerCase();

if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’){

return userInput;

} else {

console.log(‘Error!’);

}

};

function 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 was a tie!'

}

if (userChoice === ‘rock’){

if (computerChoice === 'paper'){

  return 'The computer won!'

} else {

    return 'The player won!'

  }

}

if (userChoice === ‘paper’){

if (computerChoice === 'scissors'){

  return 'The computer won!'

} else {

    return 'The player won!'

}

}

if (userChoice === ‘scissors’){

if (computerChoice === 'rock'){

  return 'The computer won!'

} else {

    return 'The player won!'

}

}

}

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

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

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


Here is a pastebin of my code just in case the forum formatting messes with it.

1 Like