What if choice1 is scissors? Why isn't this working?


#1

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

I don't understand where my code isn't working. I've looked at other answers where they said their code worked and I can't find any differences. I might be missing something, but either way, please help me figure out where this is going wrong. It's saying that I have a syntax error.

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

compare(userChoice,computerChoice);

#2

this line:

else if (choice1 === "paper") {

has no matching closing curly bracket (})


#3

As stetim94 pointed out, that section is the problem. You actually have an ending curly brace up higher there that is in the wrong place, so you technically have the right number, you just need to put them in the right places. If you indent/format your code the same way every time, it may be easier for you to tell when something like this is a problem. .


#4

Thanks for the help. It worked after I moved the ending curly bracket to the right place.