Need help finding my error. "What if choice1 is paper"


#1

var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return "The result is a tie!";
}
// I'm getting a syntaxError: unexpected token else
else if (choice1 === "rock") {
if (choice2 === "scissors")
return "rock wins";
}
else {
return "paper wins";
}
else if (choice1 === "paper") {
if (choice2 === "rock")
return "paper wins";
}
};


#2

This is your code with proper formatting:

var compare = function(choice1, choice2) {
  if (choice1 === choice2) {
    return "The result is a tie!";
  }
  // I'm getting a syntaxError: unexpected token else
  else if (choice1 === "rock") {
    if (choice2 === "scissors")
      return "rock wins";
  } else {
    return "paper wins";
  // this else if is preceeded by else statement
  } else if (choice1 === "paper") {
    if (choice2 === "rock")
      return "paper wins";
  }
};

Take a look at my comment. else ends the whole if ... else if ... else construction.


#3

Hmm. I wrote it exactly as shown and copy/pasted it and I'm still getting the same
Error msg.


#4

I have posted your code with my comment. Seriously, I can't help you if you are not able to read the answer.


#5

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