Problem with syntax?


#1


#2

Hey mate, from a coding perspective, I'm not sure if this makes a huge difference by my semicolons are after my return codes not the braces.

eg. return "The result is a tie!";

The second thing I would say is that you haven't followed the instructions for the second 'else if' where choice2 === rock, not scissors. Give that a go and see if that works?


#3


oh no, i still can't get it... @megarockstar25205


#4

Hey @lollypopheh77, apologies I didn't spot this before but you might want to double check your coding convention for how you use if/else statements.

If you run through every piece of code, you're missing quite a lot of opening and closing braces. Remember for each 'if', 'else if' and 'else' statement that you establish, you open and close brace. Double check that and try again? :slightly_smiling:


#5

its still wrong, whats wrong with my code? thanks! @megarockstar25205


#6

Hey @lollypopheh77, it's best if you go back and review your if/else codes. What you've done there is added too many braces and it looks quite chaotic. Go back and take a look but here's the basic skeletal structure to help you understand better (best not to copy just from mine but to really understand what you're trying to achieve):

variable = function ( x, y ) { <--- This is your first opening brace to start using your function
if ( x ==== y ) { <--- This opening brace begins your 'if' statement
return "blahblahblah"
} <--- This closes our your 'if' statement
} <--- This is your second closing brace

Hope that's clearer but I'd strongly suggest you review if/else statements before continuing :slightly_smiling: Good luck!


#7

Hi @megarockstar25205, thanks for all your help! I finally got it!!:slightly_smiling:


#8

Hi,

I seem to have the same problem but I managed to get all the semicolons and brackets in the right places but I am still getting nowhere. Can you review my work for lesson 7 and see what I've done wrong? Thanks in advance for your help.

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


#9

Hi,

I seem to have the same problem but I managed to get all the semicolons and brackets in the right places but I am still getting nowhere. Can you review my work for lesson 7 and see what I've done wrong? Thanks in advance for your help.

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

hey @designrockstar94307, here is my 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";
}
}
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)