Another 'What if choice1 is paper' syntax error. help!


#1


Stuck at "What if choice1 is paper?"


SyntaxError: expected expression, got keyword 'else'.. I've looked this over so many times and can't figure out what I'm missing.


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

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


#2

You have interrupted the compare function from evaluating all of the choice1 options with a single semicolon. Remove it and see if your code runs.


#3

I removed the ; but it didn't help. I'm still receiving the same error.

EDIT: Ah! I didn't see the ; in the middle, I removed that and it worked. Thank you!


#4

the code keeps telling me something is wrong with my syntax but I can't find out what. Can someone help me please?

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


#5

For this exercise, you will have if/else statements nested INSIDE else if statements. They will look something like this:

else if(something === thing){
if (some code=== thing){
return "code wins";
} else {
return "blank wins";
}
}

Study this template. Look at the curly braces. Look at the semicolons. Look at the quotation marks. All are there for a reason. Do google searches. Study answers on the CA forums. Pay attention to explanations by moderators.


#6

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