Help, please with if choice1 is paper


#1

Could you help me with this code ?

var compare = function(choice1, choice2) {
if(choice1 === choice2)
{
return "The result is a tie!";
console.log("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";
        }
}

};


#2

this bit of code:

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

your else should be nested inside your else if


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

I did but still the same syntax error.


#4

nope, now you made it even worse. Now you even closed your function to early. You had this:

else if (condition){
  if (condition){
    // do something
  }
} else {
  // do something
}

it should be:

else if (condition){
  if (condition){
    // do something
  } else {
  // do something
}
}

if and else should be nested inside else if, before starting your next else if


#5

Thank you, I appreciate your answer. It was very helpful.


#6

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