I need help with number 6


#1


#2

Hey @scasillas15! You forgot to close your function. So just add a bracket at the end :smile:


#3

@scasillas15,

...and remove the semi-colon-; from your IF ELSE-IF statement structure
as a semi-colon-; is an End-of-Statement indicator for the Javascript Interpreter.

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on:

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

#4


#5

If you'd posted code instead of a screen shot I could have copy and pasted important parts :wink:
Anyway I guess the problem is your first if. There you missed the {} after the condition. See this link for further explanation why this is ok but should be used with caution:


which leads to the problem that the } closes your function. So as the if is inside of the function and the else if is outside of it there is no connection between those two and therefore the else comes unexpected. Why it complains about the else and not about the else if is btw also explained in the link. If you have further questions about this feel free to ask.


#6

I'm sorry. I can't really understand. I'm only in fourth grade. Anyways here is my code in case you want to copy and paste.

/*var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);*/

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

Do you mean instead of if(choice1 === choice2) I should say if(choice1 === choice2) { ??? cause I tried that and it does not work.


#7

I appreciate you taking your time to answer my questions. Thanks.


#8

Do you mean instead of if(choice1 === choice2) I should say if(choice1 === choice2) {

yes. And you need to add a } at the end (before the one with the semicolon) as you lack one to close the function. About the { on the first error you could have a look at the link. In short it is allowed to omit them if the next statement is really just one line, because if you omit them the condition only works on the next line. The problem in your case is that the upcoming } will in this case match with the { of your function. Which leads to the problem that the whole rest which should be inside of your function is now outside of it and that causes a lot of errors.


#9

Hi... i'm in a problem quite similar of scasillas15.

what's wrong there. i've watched and i think they're similar.. :confused:


#10

You have semicolons where they should not be. In particular after conditions.
I wrote a post about this so maybe this is helpful:


#11

Oh thx it worked. :grinning: