9/9 "Rock, Paper, Scissors, Rope"


#1

Here is my code:

var userChoice = prompt("Do you choose rock, paper, scissors or rope?");  
var computerChoice = Math.random();
if (computerChoice <= 0.25) {
    computerChoice = "rock";
}
else if(computerChoice <= 0.5) {
	computerChoice = "paper";
}
else if(computerChoice <= 0.75) {
    computerChoice = "scissors";
}
else {
    computerChoice = "rope";
};
console.log("Computer: " + computerChoice);
var compare = function(choice1, choice2) {
    if(choice1 === choice2) {
        return "The result is a tie! Make another choice.";
        console.log(userChoice);
    }
    else if(choice1 === "rock") {
        if(choice2 === "scissors") {
            return "rock wins";
        }
        else if (choice2 === "paper") {
            return "paper wins";
        }
        else {
            return "rope wins";
        };
    }
    else if(choice1 === "paper") {
        if(choice2 === "rock") {
            return "paper wins";
        }
        else if(choice2 === "scissors" {
            return "scissors wins";
        }
        else {
            return "paper wins";
        };
    }
    else if(choice1 === "scissors") {
        if(choice2 === "paper") {
            return "skissors wins";
        }
        else if (choice2 === "rock") {
            return "rock wins";
        }
        else {
            return "rope wins";
        };
    }
    else if(choice1 === "rope") {
        if(choice2 === "scissors") {
            return "rope wins";
        } 
        else if (choice2 === "paper") {
            return "paper wins";
        }
        else {
            return "rope wins";
        };
    }
    else {
        return "Error. Choose one of proposed variants";
        console.log(userChoice);
    };
};
console.log(compare(userChoice, computerChoice));

SyntaxError: Unexpected token {

Where is mistake?


#2

There are no semicolons after else and anything directly after a return statement doesn't make any sense as it is unreachable for example:

else {
    return "Error. Choose one of proposed variants";
    console.log(userChoice); // cannot be reached
};// not necessary

Also the Syntax error is caused by the interpreter not by the author so this is not a bug on the page but in your code:

else if(choice1 === "paper") {
        if(choice2 === "rock") {
            return "paper wins";
        }
        else if(choice2 === "scissors" { // missing the closing ) here
            return "scissors wins";
        }

#3

Thanks, now it works corectly,exept restarting the game.