What if choice1 is rock? Unexpected end of input


#1

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/2?curriculum_id=506324b3a7dffd00020bf661


SyntaxError: Unexpected end of input

I keep getting this error so I checked my code against the hint that was available but it looks the same so I'm a bit lost, any insight? Please assist and thank you 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";}}


#2

Cramping your code together like that makes it a lot more difficult to tell if something is missing. Consider using this style instead:

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

The error message, SyntaxError: Unexpected end of input is saying that the code ended when it was expecting something else first. See anything missing at the end?


#3

I took your advice on changing up my format and found the issue almost immediately. I can't believe one extra curly bracket at the end kept me stuck on this part for so long! Thank you very much!


#4

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"; }
}
SyntaxError: missing } after function body
What the heck am I doing wrong?


#5

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