What if Choice 1 is paper? I need help!


#1

I'm having trouble! My code is:
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";
}
}

and it comes up as SyntaxError: Unexpected end of input.
Any help would be appreciated!


#2

this opening curly bracket:

var compare = function (choice1, choice2)
{ <- this one

doesn't have a matching closing curly bracket, i will leave it to you to figure out where it should be


#3

Yes it works, thanks so much! I've been stuck on this one for so long.


#4

I'm also having some syntax issues. This is my code

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

I can't figure out what I'm missing


#5

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

you close your else if statement, you shouldn't. the order should always be if, else if and finally else. the if and else are nested in else if, otherwise the order doesn't work. Else is always last, same with your other else if statement


#6

Sorry about the delay in replying. I believe I made the changes you suggested but i'm still receiving an error. My code looks like this now.

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

#7

you forgot to close the function with a }; at the vey end


#8

Line 18 - return "scissors wins"; <* Was missing ; *>
Missing ending }; on Line 21