Rock Paper Scissors 4/9

#1

It keeps saying
SyntaxError: Unexpected token {
cant find the problem

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

Appreciate the help guys/girls

#2

Hi, there are may mistakes your code, so I have copied the right one. Please compare them.

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

else {
computerChoice = "scissors" ;
}``````

#3

Is there a particular reason you multiply it by one here?

``var computerChoice = Math.random()*1;``

for obvious reasons its the same as without it, isn't it? The rest is good just wondering about that line.

@ruebbali
Your problems are these two statement:
First of all this one:

``else if (0.33<computerChoice<0.66) {``

this does not work. What it does is to execute them in order so first `0.33 <computerChoice` and the result of this (either true or false) compared to 0.66. `true/false<=0.66` unfortunately even works as true as a numerical value of 1 and 0 of false. So if you think it through this ends up in a logical error meaning this case is not chosen if computerChoice is > 0.33 also it might be correct but it is chosen if it is below 0.33 although this is 100% incorrect.

To avoid this either use `condition1 && condition2` to chain two individual conditions together (&& stands for AND meaning that both need to be true to make the overall condition to be true) or you can have a look at @pointphoton's post and think of why it is sufficient to do this

last but not least the other problem:

``  else ( computerChoice > 0.66) {``

as else is the default case it does not require a condition and using a condition anyway might turn out to produce unwanted or even harmful behaviour. More information on how this works can be found here: