What if Choice 1 is scissors?


#1



I'm guessing I am missing a curly bracket, but I can't figure out exactly where. Any help?


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

SyntaxError: Unexpected token else


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


#2

@datapro87479,
Your assumption of a missing closing curly-bracket-} was correct...
It is your 2nd ELSE-IF code-block which is not closed
like

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

#3

else if (choice1 === "paper") {
if (choice2 === "rock") { //<<-- missing {
return "paper wins";
}
else {
return "scissors wins";
}
} //<<-- missing {
else if (choice1 === "scissors") {
if (choice2 === "rock") {
return "rock wins";
}
else {
return "scissors wins";
}
}
}; //<< missing semicolon

console.log(userChoice, computerChoice);


#4

Thank you! I was able to go to the next lesson following your code. Now I just need to figure out how it worked!:slight_smile: I just wasn't applying all of those brackets that you have pointed as missing.