What if choice1 is paper?


#1

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#


What condition am I missing to make this code 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{
     return "paper wins";  
    }
    **if (choice1 === "paper"){**
**    }**
**    else if {**
**    if (choice2 === "rock"){**
**    return "paper wins";**
**    }**
**    else {**
**        return "scissors wins";**
**    }**
};


#2

I don't think you are missing any conditions with your code. The only immediate thing I can see is that the curly bracers are a bit wrong.
You need to put your second if and else inside the curly bracers of your first else if. And then you need one extra curly bracer at the bottom. Use my code below as a reference.

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

However I cannot be certain without seeing your error message. If that wasn't the problem please quote your error.

But if that made your code work please mark my reply as the solution. :slight_smile:


#3

Check your braces. The model to follow is,

if () {

}
else if() {
    if () {

    } else {

    }
}
else if ...

#4

I have revised the code to follow the provided model, but receive an mark up on the code

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


#5

The example above is missing a closing brace before else if.


#6

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