Syntax error when i use > or <


#1

how come it says that < and > are unexpected tokens?


#2

Depends on how you use it. Put a > or < in the middle of nowhere in your code, then yeah, it's a syntax error.


#3

I'm on the computer choice part two but here is what i have.

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


#4

These two gives syntax errors.

Reason 1:

No requirement for an else statement.

Reason 2:

Commas are syntax errors, because they are something that JS doesn't know.:smiley:

Reason 3:

You can just put computerChoice < 0.66 instead of putting the 0.33 and 0.66 thing together, because you can't. Unless you use &&, but don't use it. :smiley:


#5

thx for the help :grinning:


#6

Just an additional to reason two. There actually is a comma operator in javaScript (not covered in the track) which chains two statements together and gets it's value from the second one so for example:

name = value, name2 = value2;

would execute both but treats them as one statement (similar to the {} counting as one statement) and would have a value of value2.