SyntaxError: Unexpected token else


#1

Hi, i'm trying to find out the problem, but still can't . Do you have any advice for me?


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"
  };
    
    
console.log(compare)


#2

When would it be expected? Probably got one in a different situation from that
Fixing the formatting would make it easier to spot:

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


    console.log(compare)

#3

7.What if choice1 is paper?

your code doesn't match


#4

You mean your code?
I posted your code. That was the point.


#5

Yes, now it looks clear, but i still can't understand the problem


#6

Which one?
The syntax error message?
When would an else be expected, did you consider that?


#7

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