7. What if choice1 is paper? Got stacked


#1


Hello everyone. I've checked all the topics on the forum with the same issue, but still can't find a solution. I absolutely don't see where I am mistaken. Then I copypasted the completed code from exercise "8." and still have the message "SyntaxError: Unexpected token else"

Link

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

Uploading...


#2

your else if choice1 equals rocks doesn't have a matching } to close the else if statement before moving on to the next else if statement.

your function:

var compare = function (choice1, choice2) {

the { of the function doesn't have a matching }


#3

So, should be like this?

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

doesn't work either


#4

} which close else if statements shouldn't have a semi-colon

your function still doesn't have a closing curly bracket, at it at the end.


#5

Thank you very much! ^^
Without your help I wouldn't notice a mistake.


#6