7. what if choice1 is paper?


#1

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661

my code is spitting out:
SyntaxError: Unexpected keyword else

Not sure what's wrong with my code! Please help!


var compare =function(choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
    }
        else if (choice1 === "rock") {
         if (choice2 === "scissors") {
            return "rock wins";
        }
    }
            else {
                return "paper wins";
    }
        else if (choice1 === "paper") {
         if (choice2 === "rock") {
            return "paper wins";
        }
    }
        else {
         return "scissors wins";
    }
}


#2

you should nest the if and else inside else if. else if check choice1, then if and else check choice2:

if (condition){
  else if (condition){

  } else {

  }
}

see how i nested if and else?


#3

4 posts were split to a new topic: 7. what if choice1 is paper


#5

Ah, Thank you so much! In lesson 6 it had passed my code and told me all my syntax was right so I hadn't even bothered touching the top part. quite confusing!


#6

Did you solve the problem?


#7

yes, thank you! it was just what you said.


#8