HELP! What if choice1 is paper? 7


#1

Can someone help me with my code for part 7 of Build "Rock, Paper, Scissors" - What if choice1 is paper? I am getting syntax error. My code is below:

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

#2

I try to write code again and it seem to work this time:

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

#3

Yes this time the else belongs to the inner choice2 comparison instead of the outer choice1 else if which is very important as otherwise the first else ifs else would make the whole following code redundant because the else would cover all cases.