What if choice1 is paper?


#1

//i have no idea what i am doing wrong someone please help

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

else if (choice1 === "paper") { //this is where i get error

if (choice2 === "rock") {

return "paper wins";
} 
else {

return "scissors wins";
}

}
}
};


#2

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 "papers wins";
   } 
} // was missed } 
else if (choice1 === "paper") { //this is where i get error
   if (choice2 === "rock") {
      return "paper wins";
   } else {
      return "scissors wins";
   }
} 
} // extra }, must be removed
};

#3

thank you that helps so much because i get that error so often


#4

To avoid that errors use spaces. Example:

if (time < 10) {
    greeting = "Good morning";
} else if (time < 20) {
    greeting = "Good day";
} else {
    greeting = "Good evening";
}

More examples: JavaScript If...Else Statements


#5

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