What is choice1 is paper?


#1

Can someone help. I am stuck here with error SyntaxError: Unexpected token else.

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";
}
//What if choice1 is paper starts here below
else if (choice1==="paper"){ //No retuen value on this logic
if (choice2==="rock"){
return "paper wins";
} else {
return "scissors wins";
}
};


#2

HI this line your dind't close the else if statement

else if(choice1==="rock") {
    if(choice2==="scissors")
        return "rock wins";
    } 
    else {
        return "paper wins";
    }
} <-- add this one }

the here you didn't close the compare function

    else if (choice1==="paper"){ //No retuen value on this logic
        if (choice2==="rock"){
            return "paper wins";
        } 
        else {
            return "scissors wins";
        } 
    };
}<-- add this one }

#3

Thank you. Didi that. See below.
//First section that I think I got right
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";
}
}
//What if choice1 is paper starts here below
else if (choice1==="paper"){
if (choice2==="rock"){
return "paper wins";
} else {
return "scissors wins";
}
};
}
However, get thee error "SyntaxError: Unexpected token else
"


#4

This line

if(choice2==="scissors")
    return "rock wins";
}

its missign the open { to the if statement


#5

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