SyntaxError: missing before statement


#1



Build "Rock, Paper, Scissors"
Computer Choice: Part 2


SyntaxError: missing before statement


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

Please help me to find out the mistakes I made from the current code above. .

Besides, I have several questions about this exercise. Please help me to answer them.
1. It is said: "If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".". So, in my initial code (before I changed to the one above) I wrote it like that:
if (0 <= computerChoice <= 0.33 ) ...
and the next so on:
else if (0.34 <= computerChoice <= 0.66)....
But it returned the error. The question is why this version is not correct? I mean the part of code inside the parenthesis.

Thank you so much.


#2

@name2889,
An ELSE statement does not take a condition
Thus change your

else computerChoice <= 1 {

into

else  {

#3

Thank you for your answer, it helped. Could you explain why we can not use as a condition "0 <= computerChoice <= 0.33", instead we use "computerChoice < 0.34"? I did not quite understand the logic... :pensive: Thanks.


#4

@name2889
Have a look at

+++++range division problem ++++++++++++++++++++++++++++++++
     0         0.33          0.34         0.67        0.9999
     | range1   | lost-range   |  range2    |   range3   |
     |    IF    |      ???     |  ELSE-IF   |    ELSE    |

#5

Thanks. Then how about this one:
if (0 <= computerChoice <= 0.33 ) ...
and next
else (0.33 < computerChoice <= 0.66)...
and so on.
I understand, that in this particular case my formulation is not proper. Because it is already set, that Math.random() can be only between 0 and 1. I am asking just for curiosity.

Anyway, I understood the logic, i.e. using one condition, we automatically exclude it from using in the next conditions.
Thank you.