Stuck on both choices are the same - Need help


#1

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

It says the return is outside of the function :confused:

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

#2

You have mismatched curly brackets that made if/else part outside of your function.
Look at the snap and

where I rounded -- Delete it
Where I made an arrow -- > Add a closing curly bracket }


#3

It now says that I have a missing semicolon and an unnecasary semicolon.


#4

Don't put any semicolon inside the function after any if/else (You still need to add semicolons after every statements inside if/else clause).
Though after finish of function(at very last curly bracket) put a semicolon.


#5

This is my code now.

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

if(choice1 === "rock"); {
if(choice2 === "scissors"); {
return "rock wins"
}
else; {
return "paper wins"
}
};


#6

Hmm...I think my statement was not explicit much and you did just opposite of what I said.

well lets purify your code..

var compare = function(choice1,choice2) } < -- It should be { 
if (choice1 === choice2); <-- delete this semicolon {
return "The result is a tie!" <-- put a semicolon here
}

if(choice1 === "rock"); <-- delete this semicolon {
if(choice2 === "scissors"); <-- delete this semicolon {
return "rock wins" <-- put a semicolon here
}
else; <-- delete this semicolon {
return "paper wins" <-- put a semicolon here
}
}; <-- delete this semicolon and add  } after this then add semicolon

#7

It worked! Thanks so much!


#8

I'd suggest you to go to these two links and read about conditional statements and function.

Conditionals
Functions


#9

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