What is wrong with my code?Unexpected token else Help?


#1


I'm so confused. I typed seemingly correct code and even made it look like the hint and I am still getting a syntax error. If anyone can help me out I would be so grateful as I really want to progress onwards!

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

SyntaxError: Unexpected token else

Replace this line with your 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";
    }
}


#2

; after if condition is a bad idea

if (choice1 === choice2); // remove ;


#3

HI And you should add one } at the end for closing the compare function


#4

Thank you both but I am still getting the unexpected token else error, do you know what causes this?


#5

can you post your new code?


#6

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


#7

i"m trying to figure out a better way to paste it


#8

About how to format the code you can read it here

then in your code now you didn't close your first if statement

..
if (choice1 === choice2) {
    return ("The result is a tie!");
#you should close the if statement here.. }
else if (choice1 === "rock") {
..

#9

I got it. Thank you so much for your support!


#10

please help, I'm having the same problem with my code, the computer is not having it for some reason. Whats wrong with this code?

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


#12

HI this line

return "the reuslt is a tie!";

you wrote reuslt instaed of result


#13

haha im so stupid thank u


#14

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