Part 8. Choice 1 Scissors


#1


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

I'm getting SyntaxError: Unexpected token ILLEGAL. I've spaced out the code with braces on their own lines, but I can't seem to figure out what I'm missing or what I added that shouldn't be there.


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";
            } 
    
    }    
        else if (choice1 === "scissors") 
            {
    if (choice2 === "rock") 
        {
                return "rock wins; 
            }
        else 
            {
                 return "scissors wins";
                    }
            
        }
};
compare(userChoice, computerChoice);


#2

return "rock wins;

That line has an error, can you see it now?


#3

I added the missing quotation mark and now I'm getting the error: "SyntaxError: Unexpected token else". What else might be the problem?


#4

When I copy/paste your code and add the missing ", I get this error:

ReferenceError: userChoice is not defined

That is because the earlier code where we defined userChoice and computerChoice were missing. When I added that code back in there were no more errors.


#5

--- You have your user userChoice and computerChoice code after the }; instead of before. So instead of having:
else
{
return "scissors wins";
}

    }

};
compare(userChoice, computerChoice);

--- It should be:

else
{
return "scissors wins";
}

    }

compare(userChoice, computerChoice);
};

--- Changing this it should work.


#6

You don't really want to call the compare function from inside itself. Do you see how that would just keep running and running and never stop?