Syntax error unexpected if


#1

Where did i mess up at on my code

var compare= function
    if ( choice1===choice2 ){
    return "its a tie";
}

    else if(choice1===rock){
        if(choice2===scissors)
        return "rock wins";
}
    else if(choice1===paper){
        if(choice2===scissors)
        return "scissors win";
}
    else if(choice1===rock){
        if(choice2===paper)
        return "paper wins";
}

#2

Seems like your missing the second option for your cases. For example think of what happens if choice1 is "rock" but choice2 is not "scissors". Have a look at the link of 6/9 for an example how this can be done.

Also you need to use "rock", "paper" and "scissors" without the "" they would otherwise be treated as variable names. Also the tie message is "The result is a tie!" might cause problems as well idk. Last but not least you missing a } to close the function at the very end.


#3

var compare= function

Remember you need a parameter " () " and an opening / closing bracket. " {} "

var compare= function() {
  //Code here
}

#4

Also, I didn't notice this until now, You're also missing opening and closing brackets for your nested if statements, and as @haxor789 mentioned, missing the "else" if statement. As well as the quotation marks around "rock", "paper", and "scissors".

else if (choice1 === "rock") {
   if(choice2 === "scissors") {
      return "rock wins!";
   }
   else {
      return "paper wins!";
   }
}
//and so on