Rock Paper or scissors JavaScript project has paper beating scissors and I can't figure out why?

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

I have been scratching my head as to why my code is not working. Every other function works properly, however when it checks if userChoice is paper and computerChoice is scissors it returns the else statement telling me I won, even though it should clearly inform me I lost. I have painstakingly went over my code multiple times to make sure every bracket is in the right spot, and I just cannot find the problem no matter what I try.

const getUserChoice = userInput => { userInput = userInput.toLowerCase(); if (userInput === 'rock') { return userInput; } else if (userInput === 'paper') { return userInput; } else if (userInput === 'scissors') { return userInput; } else { console.log('That\'s.... not an option. We are playing rock, paper, scissors remember?') } }; function getComputerChoice() { switch (Math.floor(Math.random() * 3)) { case 0: return 'rock'; break; case 1: return 'paper'; break; case 2: return'scissors' } }; function determineWinner(userChoice, computerChoice) { if (userChoice === computerChoice) { return 'The game was a tie! Try again!' } if (userChoice === 'rock') { if (computerChoice === 'paper') { return 'The computer has defeated you in battle...' } } else { return 'You were victorious over the almighty computer!' } if (userChoice === 'paper') { if (computerChoice === 'scissors') { return 'The computer has defeated you in battle...' } else { return 'You were victorious over the almighty computer!' } } if (userChoice === 'scissors') { if (computerChoice === 'rock') { return 'The computer has defeated you in battle...' } else { return 'You were victorious over the almighty computer!' } } }; const playGame = () => { const userChoice = getUserChoice('paper'); const computerChoice = getComputerChoice(); console.log('You chose: ' + userChoice); console.log('The computer chose: ' + computerChoice); console.log(determineWinner(userChoice, computerChoice)); }; playGame()

Hi there,

So you have:

function determineWinner(userChoice, computerChoice) {
  if (userChoice === computerChoice) {
    return 'The game was a tie! Try again!'
  } if (userChoice === 'rock') {
    if (computerChoice === 'paper') {
      return 'The computer has defeated you in battle...'
    }
  } else {
      return 'You were victorious over the almighty computer!'  
    }

  
  if (userChoice === 'paper') {
    if (computerChoice === 'scissors') {
      return 'The computer has defeated you in battle...'
    } else {
      return 'You were victorious over the almighty computer!'
    }
  }

  if (userChoice === 'scissors') {
    if (computerChoice === 'rock') {
      return 'The computer has defeated you in battle...'
    } else {
      return 'You were victorious over the almighty computer!'
    }
  }
};

There is some confusion going on because of one small issue with the } … Carefully look at the code and make sure the curly brackets are all matching (or needed) accordingly!

Thank you so much for the sanity check, lol! I finally see the problem. I had to delete a bracket and add one in to this pesky block of code like so:

if (userChoice === "rock") { if (computerChoice === "paper") { return "The computer has defeated you in battle..."; } else { return "You were victorious over the almighty computer!"; } }

Thanks Again!

1 Like