What if choice1 is scissors - SyntaxError = unexpected token else


#1


SyntaxError = unexpected token 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";
        };
    };
    else if (choice1 === "paper"){
        if (choice2 === "rock"){
            return "paper wins";
        };
        else {
        return "scissors wins";
        };
    else {
        if (choice2 === "rock") {
            return "rock wins";
        };
        else {
            return "scissor wins";
        };
    };
};
console.log( compare( userChoice,computerChoice) );


#2

Hi try that remove the ; after the closing } if the if statement to it all.

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

And this part you didn't close the else if statement }

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

#3

It still did not 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";
};
};
else if (choice1 === "paper"){
if (choice2 === "rock"){
return "paper wins";
};
}
else {
return "scissors wins";
};
else {
if (choice2 === "rock") {
return "rock wins";
};
else {
return "scissor wins";
};
};
};
console.log( compare( userChoice,computerChoice) );


#4

Here remove the ;

var compare = function (choice1, choice2){
    if (choice1 === choice2) {
        return "The result is a tie";
    };  <== this one
    else if (choice1 === "rock"){
        if (choice2 === "scissors"){
            return "rock wins";
        }
        else {
        return "paper wins";
        };
    };
    else if (choice1 === "paper"){
        if (choice2 === "rock"){
            return "paper wins";
        }; <== this one 
        else {
        return "scissors wins";
        };
} <== here you missing the closing of the else if statement 
    else {
        if (choice2 === "rock") {
            return "rock wins";
        }; <== this one 
        else {
            return "scissor wins";
        };
    };
};

#5

thank you very much, but it still says that there's a problem with the syntax


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

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";
};
};
else if (choice1 === "paper"){
if (choice2 === "rock"){
return "paper wins";
};
}
else {
return "scissors wins";
};
}
else {
if (choice2 === "rock") {
return "rock wins";
};
else {
return "scissor wins";
};
};
};


#6

Hi this parts

else if (choice1 === "paper"){
if (choice2 === "rock"){
return "paper wins";
};  <== remove the ";"
} <== You should remove that
else {
return "scissors wins";
};
}

2
This part should begin with else if like the others

else { <== this should be else if too
if (choice2 === "rock") {
return "rock wins";
}; <== remove ";"
else {
return "scissor wins";
};
};