What if choice1 is paper? (Solved)


#1


Link to the exercise: https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#


Keeps saying "SyntaxError: Unexpected keyword 'else'"

Update: Solved. What worked for me was deleting the entire section that was used the in previous moduele of "What if choice1 is rock?"
So deleting all of:

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


var compare = function(choice1, choice2) {
    if (choice1 === choice2) 
    {

    return "The result is a tie!"

    }

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

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


}


#2

Hi @mimso2,

If it may help please see the code sample below. In short you had a visit from the syntax gremlins :slight_smile:
A few changes around and you should be good to give this a whirl :slight_smile:
The comments indicate the significant changes outside of some formatting and tidying up like semi-colons etc.

var compare = function(choice1, choice2) 
{
    if (choice1 === choice2) 
    {
        return "The result is a tie!";
    }
    else if (choice1 === "paper") 
    {
        if (choice2 === "rock")
        {//add opening mested IF brace
            return "paper wins.";
        } 
        else 
        {
             return "scissors wins.";
        }
    }//add closing ELSE IF brace    
    else if (choice1 === "rock") 
    { 
        if (choice2 === "scissors")
        {//add opening mested IF brace
             return "rock wins.";
        } 
        else 
        {
          return "paper wins.";
        }
    }//add closing ELSE brace  
};

#3

Thank you; this also worked.


#4

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