6/9 Coudnt find error, need help


#1

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

What is wrong with my code??


#2

Hi @ajaxpro88343,

If it may help please see the code example below. In short you had just one tiny error here, the else condition does not perform any checking of sorts, instead you need to use an else if, a quick update to your code and you should be rocking and rolling.

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

#3

If you have 3 or more situations, you should use
'if', 'else if' and 'else'
instead of just if and else.
This is because 'else' already marks the end of the situations, you can't use it multiple times or with an argument between brackets()


#4

big, huge, thanks) code works now!!!!!!!