Rock - Scissors - Paper: SyntaxError: missing before statement


#1

I wanted to make this part more granular for the ease of reading, specifing exactly the ranges. Problem is it keeps telling me is a syntax error, maybe I'm just too tired or just blind but what is wrong here ?

Text version:
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);

if (computerChoice >= 0.00 && computerChoice <= 0.33) {
computerChoice = "rock";  
}

else if (computerChoice >= 0.34 && computerChoice <= 0.66) {
computerChoice = "paper";  
}

else (computerChoice >= 0.67 && computerChoice <= 1) {
computerChoice = "scissors";  
}

#2

It is if/else if/else and not if else/if else , isn't it ? (to my point of view -I m trying to find it at the moment !)


#3

Same thing, for a moment I thought maybe it could work as in python this can be the form but nope, same thing. "syntax error" :frowning: . I will probably take the code brick by brick until i find the problem.....I want this form.


#4

If i remove the else and else if lines it works (and ofcourse it asks me for the if and else if) , when I add the else and else if lines ...syntax error, debugg mode again ....


#5

I apologize ! I made a mistake : Yes you're right it is a 1) IF , 2) ELSE IF ,3) ELSE statement .
But for me the problem was not here : it was to display the "between" 0 and 0,33 and the 0,33 and 0,66 ...
The right syntax


#6

Frickin' ■■■■, after i debugged it line by line I found the problem:

The problem was I was expecting "else" to take a condition . Problem is "else" does not take a condition, only IF and ELSE IF ....although is a bit weird I get the logic as ELSE it is "everything else".

Correct code for granularity:

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

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