8. What if choice 1 is scissors? SyntaxError


#1


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


SyntaxError: expected expression, got keyword 'else'

I'm assuming it's a missing bracket, but can't find it.
Would appreciate some fresh eyes to help me see what I am not.


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


#2

It says there's an else out of place, so just check them all.
Start by fixing your formatting.


#3

I sucked it up and really cleaned it up and found the problem, Thanks!


#4

Here you were asking for that kind of mistakes, but sometimes syntax errors happen even when keeping things tidy and "check them all" is of course not the most efficient approach. Interpreters usually give a line number at the location where it is no longer able to make sense out of the code. Codecademy doesn't do that, but one can always run it in another interpreter that does.


#5

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