Help 7/9


#1

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";
}
if(choice1 === choice2) {
    return "The result is a tie!";
}
else if(choice1 === "paper") {
    if(choice2 === "rock"){
        return "paper wins";
    }
    else {
        return "scissors wins";
    }
}

}
This is the output:
Oops, try again. Your code returned 'paper wins' instead of 'scissors wins' when the inputs are paper and scissors
What is wrong?


#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 "paper wins";
  } if(choice1 === choice2) {
    return "The result is a tie!";
  } else if(choice1 === "paper") {
    if(choice2 === "rock"){
      return "paper wins";
    } else {
      return "scissors wins";
    }
  }
}

This is how your code look like indented. This is how it should look like.

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 if(choice2 === "paper") {
            return "Paper wins!";
        }
    } else if (choice1 === "paper"){
        if(choice2 === "scissors"){
            return "scissors wins!";
        } else if(choice2 === "rock") {
            return "Paper wins!";
        }
    }
}

Pay attention that you CAN NOT have if - else if - else and then return inside that else and expect function to continue when you write another if. Nesting is very important, try not to copy my code but look at it and understand why it is as it is. Also keep in mind that when return is called, function is terminated. What is done to that point is done, other code is ignored.


#3

You have not closed the first else if condition.
Also, you have the condition if(choice1 === choice2) twice in your code.