What if choice1 is paper?


#1

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

my code


#2

Hi @megapro94938,

If it may help please see the code sample below.
There was a few syntax error with the placement of your parens in the function, as a result it sort of cascaded down, but not to worry it's not anything we can't address :slight_smile:

As an additional note & a friendly nudge :wink:, please help others to best help you :slight_smile:
There is unfortunately no hint at what problem you are experiencing with this code/lesson. Although the reply here has taken the view that it was syntax related this may not be the case for you, so posting as much detail as you can, without info overload is really appreciated :slight_smile:
In this way not only does this help to pave the path for those who read these posts but also it helps the respondor understand what the issue is.

var compare= function (choice1, choice2) {
    if(choice1===choice2) 
    {
        return "The result is a tie!";
    }
//}; this closes your function, let's move this to the very end
    else if (choice1==="paper")
    {
        if (choice2==="rock") //{ one too many parens lets remove one, and this probably wants to be rock?
        {
            return "paper wins!";            
        }
        else
        {
            return"scissors wins";            
        }
    }
}; //we can use this extra paren down here to close the function out
//my code I guess this was just an error? heehee

//just some sample test runs
compare("paper", "rock");
//compare("paper", "paper");
//compare("paper", "scissors");

#3

hi its tricky one! took me a while.:confounded:
here is the right code;

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

#4

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