Please help i'm stuck


#1

why won't it work.
SyntaxError: Unexpected keyword 'else'

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

var compare = function(choice1, choice2){
    if(choice1 === choice2); { // syntax error: ; after condition
        return"The result is a tie!";
    }

#3

i have done that and it still won't work


#4

this should work shouldn't it?
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";
}

}
};


#5

try with a second "if statement" after the the if that returns "tie".

then inside the second if, use another if. I don't think you'll have need of "else" to make this function works.
let us know.


#6

do you mean like this?
var compare = function(choice1, choice2){
if(choice1 === choice2); {
return"The result is a tie!";
}
if(choice1 === "rock") {

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

}
};


#7

got it at last, thanks so much


#8

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