What if (choice1 is "paper") issues


#1

I am lost here on this particular exercise. If someone can tell me what I'm doing wrong or what I'm missing that would be great. Any help will be greatly appreciated. Here's the code I am having issues with.

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

Here's a link to the exercise as well.. https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661


#2

Hi @swaunyjones,

If it may help please see the code sample below.
Just a visit from the gremlins here for how you had your code logic :slight_smile:
In short, you just needed to move in the else conditions into the else if blocks, as these are part of the logic that the else if wants to perform.
A simple change on that and you should be good to rock & roll, the code otherwise is great :slight_smile:

```
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 //move this else statement into the code block for the first else if
        {
            return "paper wins";
        }
    }
   
    else if(choice1 === "paper") 
    {    
        if(choice2 === "rock") 
        {
            return "paper wins";
        }   
         else  //move this else statement into the code block for the second else if
        {
            return "scissors wins";
        }
    }
   
}

`

PS: Just as a small note it does help to include what error you are getting when asking for assistance, no complaint here just a little friendly nudge; the more information you can supply without overload always helps everyone out :wink:


#4

Thank you so much for your help. Took me a while but I figured it out. Thanks for the advice.


#5

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