6/9 problem


#1

My code looks like this and it tells me "SyntaxError: Unexpected token else" I don't get it.

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


#2

  • Change `else if` to `if`

  • Change `if` to `else if`
  • The standard format for functions is:

var functionName = function(parameter, parameter) {
  if (condition1) {
    //do something
  }
  else if (condition2) {
    //do something
  }
  else {
    //do something
  }
}

#3

In instructions it says that I should create "else if" statement first.

Inside the compare() function under the existing code, write an else if statement where the condition is choice1 === "rock".
Inside this else if statement, write an if / else statement. If choice2 === "scissors", return "rock wins". Else, return "paper wins".


#4

Here's mine:

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

#5

Oh, it should be inside compare function. Thanks man.


#6

No problem!

You should mark this topic as complete now so that you don't keep getting responses.