Problem with my code: says "Illegal return statement"


#1

I have no idea what's wrong. The hint doesn't help that much(I surmise that's on purpose).

if(choice1 === choice2) {
    return "The result is a tie!";
} else if(choice1 === "Rock") {
    if(choice2 === "Scissors") {
        return "Rock wins!";
    } else {
        return "Paper wins!";
    }
}

I'm clueless.


#2

@gigasurfer32051,
You have define the compare =function=

var compare = function(choice1,choice2) {
     // in the FUNCTION-BODY 
     //you have to define your IF ELSE-IF statement structure

    //do not forget the closing curly-bracket-} to close the function
}

your choice-strings AND return-strings should all be in LOWERCASE

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

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

#3

It's still not working. It's not making sense.


#4

@gigasurfer32051
A return statement can only be used inside a function
like

var compare = function ( choice1,choice2) {
    //Begin of the FUNCTION-BODY

    if(choice1 === choice2) {
         return "The result is a tie!"; 
    } 
    else if(choice1 === "rock") {
          if(choice2 === "scissors") {
              return "rock wins!";
          } else {
              return "paper wins!";
          }
    }
    //END of FUNCTION-BODY
};