What is wrong with my syntax? I think it's perfect!


#1


 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

Each opening brace must be matched by a closing one


#3

thanks ionatan, I didn't notice that!


#4

but what's wrong with th else if (choice1 === "paper") {
if (choice2 === "rock") {
return "paper wins";
} else {
return "scissors wins";
}is?! it's exactly the same as the previous one!


#5

sorry i'm posting it again, the first one didn't come out good

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


#6

No clue what you mean by wrong. Keep in mind that term is used to avoid describing what it's doing differnently from what you expected


#7

it keeps telling me "Oops, try again. There was a problem with your syntax." and I have no idea why!


#8

can you send your full current code if you haven't already, and a link possibly?


#9

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


#10

not sure which link you want


#11

just a link to the assignment. this lets me see my code compared to yours. you can copy and past the url or there should be a button at the bottom next to the save and submit button that lets you copy the link


#12

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


#13

yup perfect thanks. now I can look and make sure that it works before I tell you what needs to change


#14

I think your syntax is fine its just that you have the if/else if/ else statements broken up when they don't need to be.


#15

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

so it worked after I moved the bottom else if to before the three }}} and added another } right after the return statement. its kind of hard to explain but if you don't understand ill try and simplify it


#16

WOW! Thanks so much kalebmfratello (or whatever your name is) that was a
real help, I was sitting on this page for hours already!


#17

haha its Kaleb Michael Fratello. no problem, glad I could help


#18

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