-6

Here is the code:

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

I was learning java script in codecademy and after submitting the code it gets me the error saying

Your compare function doesn't return the correct string when comparing paper to rock.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Pavan Nadig
  • 1,469
  • 3
  • 11
  • 13

2 Answers2

4

choice1="paper" is an assignment, not a comparison. Use === for comparisons (unless you need type coercion, in which case use ==)

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

This should work...

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 == "Rock") {
            return "paper wins";}
       else if (choice2 == "Scissors") {
            return "scissors wins!";
       }
   }
};
James Arnold
  • 698
  • 3
  • 9
  • 22