Build Rock, Paper, Scissors Help!


#1

I'm getting an unexpected token else error. What am I doing wrong?

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 "scossors wins";
    }

};
};
};

#2

Run through the code and make sure every opening bracket has a corresponding closing bracket.


#3

All brackets have a corresponding bracket. I am now getting a syntaxError: unexpected number


#4

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

here you missed the closing } for the else if before the next else if.


#5

Still getting the same error. I must be missing something else.

var compare = function(choice1, choice2) 1{

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 "scossors wins";
    }


};
};

#6

And no semicolons after conditions as you did here:

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

Here is a link that might explaiin why this is a problem:


#7

code:
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)
{
string="The result is a tie!";
return string;
}
else if(choice1==="paper")
{
if(choice2==="rock")
{
return "paper wins";
}
else
{
return "scissors wins";
}
}
else(choice1==="scissors")
{
if(choice2==="rock")
{
return"rock wins";
}
else if(choice2==="paper")
{
return"scissors wins";
}
}
};
compare(userChoice,computerChoice);