6/9 How is my code wrong? SyntaxError: expected expression, got keyword 'else'


#1

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

}


#2

just pray to gaben and then you shall get the knife that you have been waiting for


#3
var compare = function (choice1, choice2){
if (choice1 === choice2) {
    return "The result is a tie!"
}
};

This is your whole function so the stuff coming after this complains that it is outside of the function where choice1 and 2 are not defined and return is not allowed to be used and else is not connected to the if and so on. Just wrap the stuff that comes after this in the function as well.


#4

I tried that and it still said it was wrong here I'll send you the code of me putting the if else statements inside of the compare this time.


#5

What is the error message?


#6

Hi,

not sure if you fixed this now but is syntax error signposting you to the return line in the 'if' directly above the 'else if' ?

I think it may be because there is no semi-colon after the return ?

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

try tweaking code by adding semi-colon:

if (choice1 === choice2){
return "The result is a tie!";
}

hope that helps in some way


#7

This semicolon would be appropriate but it would not throw an error if it is missing.