Rock Paper Scissors - Failing 1 case (User Paper, Computer Rock)

Hi All,

Not sure where I am going wrong in the rock paper scissors project. Getting all but one use case right. When user chooses paper and computer chooses rock - the game should say congrats you won but instead is printing computer won. Check code below -
https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-functions/projects/rock-paper-scissors-javascript

const getUserChoice = userInput => {

userInput = userInput.toLowerCase();

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

return userInput;

} else {

console.log('Error. Please type valid input');

}

}

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

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

const getComputerChoice = () => {

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

switch(randomNumber) {

case 0:

return 'paper';

case 1:

return 'rock'

case 2:

return 'scissors'

}

}

// console.log(getComputerChoice());

// console.log(getComputerChoice());

// console.log(getComputerChoice());

const determineWinner = (userChoice, computerChoice) => {

if (userChoice === computerChoice) {

return ‘This game is a tie’;

}

if (userChoice === ‘rock’) {

if (computerChoice = 'paper') {

  return "Sorry computer won";

} else {

  return "Congratulations you won!";

}

}

if (userChoice === ‘paper’) {

if (computerChoice = 'scissors') {

  return "Sorry computer won";

} else {

  return "Congratulations you won!";

}

}

if (userChoice === ‘scissors’) {

  if (computerChoice = 'rock') {

    return "Sorry computer won";

  } else {

    return "Congratulations you won!";

  }

}

};

const playGame = () => {

const userChoice = getUserChoice(‘paper’);

const computerChoice = getComputerChoice();

console.log(Computer threw ${computerChoice});

console.log(User threw ${userChoice});

console.log(determineWinner(userChoice,computerChoice));

}

playGame()

Hello @adee009, welcome to the forums!
The problem might be to do with this:

The single = sign. In JS, equality operators take two forms === and == (the second one shouldn’t be used very often-it is less stringent). But I’m surprised that that isn’t throwing an error.

Also, there shouldn’t be a semicolon at the end of the function’s curly braces ({}):

You should just have }, no semicolon. Other than that, I can’t see other problems. In future, try to preserve the formatting of the code, by pressing this button:


and writing/pasting your code in between the back ticks:Screen Shot 2020-05-02 at 14.06.13

I hope this helps!