Rock, Paper, Scissors Project

I am on step 11 of the ‘Rock, Paper, Scissors’ project where it asks you to check the ‘determineWinner’ function. For some reason when I test this, I get the same result of it being a draw each time. I have tested the variables of userChoice and computerChoice separately and they return random results each time exclusive of the ‘determineWinner’ function. Not sure where I am going wrong if anyone has any advice?

https://www.codecademy.com/courses/introduction-to-javascript/projects/rock-paper-scissors-javascript

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === computerChoice);{
  return 'draw';
  }
  if (userChoice === 'rock') {
    if (computerChoice === 'paper') {
      return "computer wins";
    } else { 
      return 'You won!';
    }
  }
if (userChoice === 'paper') {
  if (computerChoice === 'scissors') {
    return "computer wins";
  } else {
    return 'You win'
  }
}
if (userChoice === 'scissors'){
  if (computerChoice === 'rock'){
    return "comupter wins";
  } else {
    return 'You win'
  }
}
}
console.log(determineWinner('paper', 'scissors'));
console.log(determineWinner('paper', 'paper'));
console.log(determineWinner('paper', 'rock'));

There should be no semi-colon after the condition.

// You wrote:
if (userChoice === computerChoice);{
    return 'draw';
}

// It should be:
if (userChoice === computerChoice) {
    return 'draw';
}

With the extra semi-colon, your code is being interpreted as:

if (userChoice === computerChoice) {
    // Empty block
}
{  // Separate block not dependent on any condition
    return 'draw';
}

and consequently, you are always returning 'draw'.

3 Likes

Thanks for the help :slight_smile:

1 Like