Stuck on both choices are the same - Need help


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


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 }


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


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.


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"


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


It worked! Thanks so much!


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



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