Expected expression, got keyword 'else' (HELP !)


#1

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";
  }
};
compare(userChoice,computerChoice);


#2

When you get this error message, check all of your else related code blocks. See if the syntax is correct for each and if they are used in a way that allows your code to execute the way required for this exercise.


#3

if (condition) {
  // your code
} 
else if (condition) {
     if (condition) {
         // your code 
     } else {
         // your code
     }
} else if (condition) {
     if (condition) {
         // your code 
     } else {
         // your code
     }

}

Like you can see you forgot several times to close or open your if / else if / else.


#4

Thanks ! It's OK. I have a very bad english :slight_smile:


#5

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