Weird Error Message


#1


What if Choice1 is Paper?


Oops, try again. Your code returned 'scissors wins' instead of 'The result is a tie' when the inputs are paper and paper
That is The Error Message I woud like help.

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


#2

Firstly you only need to make compare a variable once and make one function in your code.

You also need to structure your code a bit differently, use mine underneath as a reference.

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

If this helped you please be so kind as to mark my answer as the solution, thanks.


#3

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