6/9 Syntax error: Unexpected end of input


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

here i am quite sure that I have typed the code correctly, but I have no idea why I cannot pass.
this is basically correct isn't it?


#2

basically yes
but at the END you are forgetting a closing-curly-bracket-} with which you close the function-body.

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on

  • the required return-strings
  • the build of the IF ELSE-IF statement-structure.

#3

I was having the same issue as you for some time as well.

I have quoted your code below, see the end curly bracket in your code (which I have made bold), that closes off from the opening curly bracket in just before the "if(choice2 === scissors)" (which I have also made bold).

However, what you and I both forgot to do was to close off the opening curly bracket just after where we declared the compare function (see the curly bracket with the * infront of it). so basically you just need to put a closing bracket at the end t close of the entire code. see below:

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

I hope this helps :smile:


#4

@joenimbus,
Have a read through the =code-convention= for the IF-statement
as written by =Crockford=
= http://javascript.crockford.com/code.html
this to optimize readabillity.....

 var compare = function(choice1 , choice2) {     
      //Begin of =compare= FUNCTION-BODY
      //
      if(choice1 === choice2) {
           return "The result is a tie!";
      }

     //== Beginning of else-if structure
      else if(choice1 === "rock") {
             if(choice2 === "scissors") {  
                    return "Rock wins";
             }
             else {
                    return "Paper wins";
             }
       }
      //== else-if structure has been ENDED

      //END of =compare= FUNCTION-BODY
    };

PS.
Please read
= http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on the required RETURN-Values