Help, please


#1

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

I have no idea what I'm doing wrong here. Please help me. syntax error: illegal return statement. Please explain what I'm doing wrong as vividly as possible.

 var compare = function (choice1, choice2) 
{
    if (choice1 === choice2);
    return "The result is a tie!";
}
if (choice1 === "rock") {
    if (choice2 === "scissors") {
        return "rock wins";
    }
    else if (choice2 === "paper"
    {
        return "paper wins";
    }
};

#3

@ayylmao8675309, you closed function body before if (choice1 === "rock"):

var compare = function (choice1, choice2) {
    if (choice1 === choice2); // syntax error: should be without ;
    return "The result is a tie!";
} // here is the end of function compare()
if (choice1 === "rock") {
    if (choice2 === "scissors") {
        return "rock wins";
    }
    else if (choice2 === "paper" // syntax error: you lost )
    {
        return "paper wins";
    }
};

Should be:

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 if (choice2 === "paper") {
          return "paper wins";
       }
   }
};

#4

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