Extra bracket?


#1



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

SyntaxError: Unexpected token {

I can't figure out where my extra bracket is!

var userChoice = prompt("Do you choose rock, paper, or scissors?");
var computerChoice = Math.random()
console.log(computerChoice)
{
if (computerChoice < 0.34) {
    computerChoice === "rock";
} else if ( 0.67 > computerChoice > 0.33) {
        computerChoice === "paper";
} else (1 > computerChoice > 0.66) { 
   computer Choice === "scissors"; 
}


#2

H This part

{ <== this one 
if (computerChoice < 0.34) {
    computerChoice === "rock";
} else if ( 0.67 > computerChoice > 0.33) {
        computerChoice === "paper";
} else (1 > computerChoice > 0.66) { 
   computer Choice === "scissors"; 
}

Remove the } before the if statement

Here

if (computerChoice < 0.34) {
    computerChoice === "rock";

you want to asign rock to computerChoice so you should put only one = do the same for the others statement.

And the else statement dont need the condition

if ( condition) {

}
else {

}

#3

I removed it, but it is still saying the same thing, and I don't understand what you mean about the condition. Sorry :frowning:


#4

Can you post your new code?


#5

Yes, here you go:

var userChoice = prompt("Do you choose rock, paper, or scissors?")
var computerChoice = Math.random()
console.log(computerChoice);
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if ( 0.67 > computerChoice > 0.33) {
computerChoice = "paper";
} else (1 > computerChoice > 0.66) {
computer Choice = "scissors"
}


#6

var userChoice = prompt("Do you choose rock, paper, or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if ( 0.67 > computerChoice > 0.33) {
computerChoice = "paper";
} else if (1 > computerChoice > 0.66) {
computerChoice = "scissors";
}

It should look like this! You forgot a few semicol, as well as puttin an if on your last else, and the spacing on you "computer Choice" on the last else if

More specifically on your first var userChoice you were missing semicolon, then again at the end of var computerChoice, then you had 1 if 1 else if and 1 else, but it should be 2 else if due to their need for a condition!!, then inside the last else you spaced you var name and also forgot the semicolon!! Other than that your code was fine, they were little mistakes that can mess the code up :wink:


#7

Hi the else statemnt shouldn't have a condition

ex

if (condition) {
    #do something
}
else {
    #do something
}

1

else if ( 0.67 > computerChoice > 0.33) {
computerChoice = "paper";
}

they aske you that

1 If computerChoice is between 0.34 and 0.66, make computerChoice equal to "paper".
instaed of putting 0.67 > before computerChoice you could do it like that

else if (computerChoice <= 0.67){
    computer = "paper"
}

#8

Thank you SO much! It worked perfectly!


#9

Thank you very much for your help!