Building Rock Paper Scissors

There is something wrong with my syntax with the following code. The red indicators state it has something to do with the else and the brackets. Can anyone find my mistake?

function getUserChoice(){
var UserInput= prompt(‘Rock, Paper, or Scissors?’);
userInput = userInput.toLowerCase();
if (userInput === ‘rock’ || userInput === ‘paper’|| userInput === ‘scissors’)
return userInput;
} else {
console.log(‘Error!’);
}

Where is the opening { for that }?

1 Like

So I figured out that the return userInput line had to be directly under the prompt line and it works properly. But I ran into another problem with the rest of my code. The output doesn’t determine a winner. This is what I have:

function determineWinner(userChoice, computerChoice){
  if(userChoice===computerChoice){
    return 'The game is a tie!';
  } if(userChoice==='Paper'){ 
    if(computerChoice==='Scissors')
  {
  return'The computer won!';
  } else {
    return 'You won!';
    if(userChoice==='Scissors'){
      if (computerChoice==='Rock'){
        return 'The computer won!';
      }else {
        return 'You won!';
      }
    }
  }
  }
}
function playGame(){
  var userChoice= getUserChoice();
  var computerChoice= getComputerChoice();
  console.log('You chose: ' + userChoice);
  console.log( 'The Computer Chose: ' + computerChoice);
  determineWinner(userChoice,computerChoice);
}
playGame();

Here is your determineWinner function, with no code changes, but spaced differently so that we can more easily see your if/else logic:

function determineWinner(userChoice, computerChoice) {
    if (userChoice === computerChoice) {
        return 'The game is a tie!';
    }
    if (userChoice === 'Paper') {
        if (computerChoice === 'Scissors') {
            return 'The computer won!';
        } else {
            return 'You won!';
            if (userChoice === 'Scissors') {
                if (computerChoice === 'Rock') {
                    return 'The computer won!';
                } else {
                    return 'You won!';
                }
            }
        }
    }
}

You have code for what to do if userChoice is Paper but what if it isn’t? You’ve crammed all of your choice logic into that userChoice is Paper block.