What if choice1 is rock?


#1

Hey everyone.

I'm just starting to learn code so haven't developed the innate ability to see my mistakes. I feel like my issue is obvious I'm just not getting it.

Can anyone see my problem?

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

}

I keep trying to submit, but it says there is a problem with my syntax.


#2

You are missing one closing } to close your function(){}. Add it at the end and you're good to go!


#3

To close a function properly, we add a semi-colon after our last curly bracket.


#4

Thank you!!

I just noticed you guys already answered this in another topic so thanks for coming over here to hep me too!!!!


#5

It is actually not needed. Since function is not a standard statement, you don't need to separate it from other code using ;. Or at least you don't need when function is declared When function is used as expression (example var foo = function(){ return "foobar"; };), then you should use ; to close the function.

So remember this

// declaration doesn't need ;
function doSomething(){
  // code that does something
}

// expression need ;
var doSomethingElse = function(){
  // code that does something else
};