Part7 Rock, Paper, Scissors HELP


#1

Here is the code that I wrote for this rock paper scissor game. It keeps returning to with a Synthax error. Could anyone point me out to what I am doing wrong.

Thanks in advance.

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

I also tried this code but still returning with the same error.

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


#3

Ok you need to be careful with your {}. In the first version:

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

the else would belong to the else if choice1 is rock statement whereas it should belong to the inner choice2 is scissors statement. Which leads to the problem that now the condition is done with the else and therefore another else if comes ... well ... really unexpected. So the second version is much better in this point:

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

}
}

unfortunately if you could } you see that there is a closing } to much which means that you close your function at that point which again leads to the problem that the following else if is not connected to the condition.