SyntaxError: Unexpected token else


#1


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


SyntaxError: Unexpected token else

Keep getting this sure my syntax is off somewhere. Any help is greatly appreciated


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

Your bracket closures makes your conditional blocks faulty. You should close the else if by adding one more curly bracket here.

You then should have one bracket less for the second else if. By the way, it's good practice to end the compare variable definition with a semi-colon.

I hope this helps! :slight_smile:


#3

You rock!!! Thanks and I will add the semi colon also....


#4

Yay! You're welcome.

Glad I could help! :wink: :blush:


#5

A great help!! I think i will just do my brackets first so I don't forget to close or add any extra ones


#7

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