"There is a problem with your syntax" but I don't know what is wrong with it


#1

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

};
compare("rock","rock")

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

Your code will never get beyond here, because in the first conditional statement it will return one of the three possibilities. Once the method returns, it effectively jumps out of the method the the point it returns.

There are a few other syntax errors such as mismatching curly braces and missing semicolons, but from knowing that your second block of code isn't being reached try to refactor your method and then come back and let us know if you have more questions! :slight_smile:


#3

I fixed it up a bit but it keeps saying I have a problem with my syntax

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


#4

You were missing 2 curly braces at the end of the else if and the nested if. The logic for comparing was a little off as well. The first if statement (choice1 === choice2) takes care of if the choices are the same. The following else if will be used if choice2 is scissors. Then, in the nested if statement choice1 will be compared to paper, this returns scissors wins because scissors beats paper. The else will be equal to rock because the previous comparisons took care of scissors and paper.

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

}


#5

Ok I got it now thank you