Unexpected token =


#1

Keeps on telling me that


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


#2

The lesson text is confusing and it results in learners going way beyond what is actually needed. First let's point out the errors in the above line:

=>    not a valid operator, should be,
>=

&     is a bitwise AND, not a logical AND, should be,
&&

=<    should be,
<=

Notice the equal sign is always on the right. This is known as a compound operator since it is made up of more than one operator token.

Now as to the confusion, the text says something about between that throws many people off, causing them to attempt all manner of logic which many simply do not understand.

expressionA && expressionB

In JavaScript we must write each as a complete expression:

if (0 < a && a < 0.34) { }

0 < a      => expressionA
a < 0.33   => expressionB

For this exercise, we can start from the lowest interval and progress upwards from there:

if (c < 0.33) {

}
else if (c < 0.66) {

} else {

}

#3

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