Help #4!


#1


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

What's wrong with my code!


#4

@thegeeeek1886

Did you mean to use commas instead of decimals for 0,33 and 0,66?


#5

@eveat do you mean i must write 2computerchoices in one condition ?


#6

Not quite. The condition you wrote to assign "rock" to the computerChoice is =< 0,33. I'm asking if you meant to write <= 0.33.


#7

Yes. Also I don't think you should use or here. First of all in JavaScript you need to use || instead of or. But you need to check if the computerChoice is bigger than 0.33 and smaller than 0.66. The and-operator is && not and.

For example if you want to do something only if the variable a is bigger or equal to 0 and smaller than 1:

if (0 <= a && a < 1) {
  //do something
}

Note that there is no semicolon between the condition and the open bracket. Also as bliff points out it's <= not =<.


#8

A post was split to a new topic: Whats wrong with this code?


#9

A post was split to a new topic: It says syntax error


#11