7. Choice 1 is paper. Incorrect else keyword?


#1



https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#


for some reason, it always says "SyntaxError: Unexpected keyword 'else'" Please help!


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);
console.log("Player: " + userChoice)
var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
        console.log("The result is a tie!");
    }
    else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            console.log("rock wins");
        } else {
            console.log("paper wins");
        }
    else if (choice1 === "paper") {
        if (choice2 === "rock") {
            return("paper wins")
        } else {
            return("scissors wins")
        }
    }
}


#2

@fibcode

else if (choice1 === "rock") {
if (choice2 === "scissors") {
console.log("rock wins");
} else {
console.log("paper wins");
}

You forget to add another } at the end of this part to close the else if statement.


#3

Here is my code. function compare(choice1,choice2){
if(choice1===choice2){
return "The result is a tie!";
}
else if(choice1 === "rock") {

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

} else {
    return "scissors win";
    }

 }

}

I found out that you logged it to the console. They want you to return it.


#4

@fibcode, just wanted to add to @unexpectedtoken’s help that you also can paste your programs in sites like labs repl.it for help locating missing brackets, semicolons, etc. on your own in future situations.


#5

Thanks so much ms frisby