Help #4!


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

What's wrong with my code!



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


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


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.


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 =<.


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


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