Ugh. Stuck on 4 part 2. Syntax error


#1


This is my code. I keep getting this error: "SyntaxError: Unexpected token {"
Not sure what I'm doing wrong here.

var userChoice = prompt("Do you choose rock, paper or scissors?");

var computerChoice = Math.random();

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


#2

An else with an condition is never good :slight_smile:

And a second issue:

if computerchoice is smaller than 0.33 or equal computerchoice is rock

if computerchoice is greater than 0.34 or equal computerchoice is scissors

How do you set computerchoice equal paper in your code?
Remember everything greater 0.34 is scissors.


#3

You can't put an condition in an else.

on third line, you can change the code 0.33 by 0.34 ----- < 0.34 (like this).
on line six (else if), change the code 0.34 by <= 67 (like this).

Being less than 0.34, it will be "rock".
Being less than and equal as 0.67, it will be "scissor".
Being more than 0.67 (no need to comput), it will be "paper".

so it will get like this:

if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissor";
} console.log("Computer: " + computerChoice);

...............

see the else?
he doesn't have a condition in it.
just a >>computerChoice = "scissor";<< (inside the { } ).
this means that if the values get by any reasons out off < 34 or <= 67, it will be scissor.

Hope it works :smile:


#4

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