7.What if choice1 is paper?


#1

Hey guys, I kindly need your help with this one:

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

SyntaxError: Unexpected token else


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 build else if statement to check for choice1, then inside the else if statements you should make if and else to check for choice2:

else if (choice1){
    if (choice2){

  } else {

   }
}

see the difference?


#3

Yes, I think I can see it, but I still get the same error when input:

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";
}
}
};


#4

you only changed for choice1 is paper, you make the same mistake for choice1 is rock


#5

I see, I got confused, because previous time while passing prev. lesson it checked and showed that everything was fine and let me continue. :confused:

Anyway, I fixed and it works. Will keep it in mind and follow the tip next time. Thanks a lot! :slight_smile:


#6