Rock paper scissors compare function 7


#1

I've tried everything and can't find what I'm doing wrong...

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

     //MISSING CLOSING BRACKET "}" HERE

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

Hope this helps!


#3

Thanks man :smile: It can be annoying how JavaScript has to be so specific. But you get used to it.


#4

No, it doesn't.
Oops, try again. There was a problem with your syntax.
SyntaxError: expected expression, got keyword 'else'


#5

Does your code look exactly like this as well king?


#6

keep getting error message with my code. It's probably a very obvious mistake and I'm not seeing it. Can somebody check my code?

var compare = function (choice1, choice2) {

if (choice1 === choice2)
{
return "The result is a tie!";
}
if (choice1 === "rock", choice2 === "scissors") {
return "rock wins";
}
else if (choice2 === "paper") {
return "paper wins";
}
if (choice1 === "paper", choice2 === "rock") {
return "paper wins";
}
else {
return "scissors wins";
}
}

Oops, try again. Your code returned 'rock wins' instead of 'scissors wins' when the inputs are paper and scissors


#7

Yes. I even tried copy-and-pasting YOUR code, and running it with AND without the closing bracket in question... and neither version was accepted.


#8

All I did was copy paste your code and indent it so I could see where the missing bracket would be. There's a possibility for more errors to occur that I did not myself see.