Help please! Stucked with Rock, Paper, Scissors, level 5. Both choices are the same


#1

var compare = function(choice1,choice2) {
if (choice1 === choice2) {
return "The result is tie!";
} else if(choice1 === "rock") {
if (choice2 === "scissors") {
return "rock wins";
}
}
else {
return "paper wins";
}
}

compare ("paper","rock");


#2

else should be inside of else if.
you closed it before

 else if(choice1 === "rock") {
if (choice2 === "scissors") {
return "rock wins";
}
} //here you closed else if

#3

thanks, but stil there is error.


#4

You will find that proper indentation and code style will often be the answer to a lot of your issues. Your code is mostly correct, except for a simple issue which was encountered most likely because of the lack of proper indentation and code style.

var compare = function(choice1, choice2) {
  if (choice1 === choice2) {
    return "The result is a tie!";
  }
  else if (choice1 === "rock") {
    if (choice2 === "scissors") {
      return "rock wins";
    } // You had an extra closing-brace here.
  } else {
    return "paper wins";
  }
}; // You needed a semi-colon here because it is a function definition.

compare("paper", "rock");

#5

Ok, thank you.:slight_smile: I resolved the problem.


#6