SOLVED Computer Choice Part 2 - Unexpected Token Else


#1



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


Hi, all,

I'm at my wits' end with this exercise. I keep getting the error "SyntaxError: Unexpected token else." Can someone point me in the right direction?


var computerChoice = Math.random();
console.log(computerChoice)
if (computerChoice>=0 && computerChoice =< 0.33)
{
    computerChoice = "rock";
    else if (computerChoice >= 0.34 && computerChoice =< 0.66)
    {
    computerChoice = "paper";
        else
        {
            computerChoice = "scissors";
        }
    }
}


#2

Why is your else statement inside your else if statement? Also, your if statement shouldn't have everything in it.

Think of the statements this way:

"For every if statement, a else statement precedes it."

That being the case, take your else statement out of the else if statement and out on its own accords, and make it where the if statement doesn't in-close everything:

if (computerChoice>=0 && computerChoice =< 0.33) {
    computerChoice = "rock";
}
else if (computerChoice >= 0.34 && computerChoice =< 0.66) {
    computerChoice = "paper";
}
else {
    computerChoice = "scissors";
}

#3

Thanks, I appreciate the help! Going from HTML to Java had me stuck in nested statements.


#4

Hi, your less than or equal to operator should be written like "<=" not "=<".

Then the code will work correctly.