What if Choice1 is Paper (Unexpected Token Else)


#1

I have absolutely no clue what is wrong. I've tried anything I can think of.

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


Replace this line with your code.


#2

The semicolon and closing curly bracket are ending your compare function prematurely.


#3

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";
     }
  }
};   // Remove curly brackets and the semicolon
  else if(choice1 === "Paper")
  {
     if(choice2 === "Rock")
     {
        return "Paper wins";
     }
     else
     {
        return "Scissors wins";
     }
  }; // remove the semicolon
// add a curly bracket to close your function
// or add a else and close than your function

#4

Thanks, you two. I finally got it. I really appreciate it.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.