Syntax Error: Unexpected Token { Please help!


#1


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


My code wont run, I am just getting an error that says "Unexpected token: {". I am confused because I believe I only have the necessary curly brackets.


var userChoice = prompt("Do you choose rock, paper, or sciccors?");
var computerChoice = Math.random(0-1)
console.log(computerChoice);

if (computerChoice<=.33) {
    computerChoice = "rock";
}
else if (computerChoice <.66) {
    computerChoice = "paper";
}
else (computerChoice >.67)  {
    computerChoice = "sciccors";
};


#2

Try writing numbers as 0.33 and no .33
And Math.random(min, max) and not min-max but you don't even need that because when you write Math.random(); by random math random returns number between 0 inclusive and 1 exclusive.
More about it here


#3

Thank you for your answer. I tried what you suggested and made some more changes. I now have this:

if (computerChoice <0.33); {
   computerChoice = "rock";
}
else if (computerChoice >0.33<0.66); {
    computerChoice = "paper";
}
else (computerChoice <=1); {
    (computerChoice = "sciccors");
}

Now I am getting another error, "SyntaxError: Unexpected token else."

Pretty sure that "else" isn't the problem. Any suggestions? Thank you again.


#4

Yes the else is problem because after the else you shouldn't have () with another statement, only the output if first 2 evaluations are not satisfied. If you want it to work just put:

else {
    (computerChoice = "sciccors");
}

And please don't put ; before { in if and else if statements. They are written as:

if(/*something*/){
  //do something
}

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.