6. What if choice 1 is rock? Don't know whats wrong


#1

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

}


#2

Fortunately it's a simple enough fix, you just don't have brackets closing out the compare function.

var compare=function(choice1,choice2) { // first opening bracket
    if(choice1 === choice2) { //second opening bracket
        return "The result is a tie";
    /* This closes the second bracket*/ }else if(choice1 === "rock") { //second opening bracket
        if(choice2 === "scissors") { //third opening bracket
            return "rock wins";
        /*closes the third opening bracket*/}else {//Opens another third bracket
            return "paper wins";
        }//closes the third bracket
    }//closes the second bracket
};//closes the first bracket

It's helpful to have a very clear syntax with your opening and closing brackets so that you can identify if one is missing. Other than that, your code works perfectly. Good luck and have fun coding!


#3

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