Help me to find correct code


what is wrong in my code below
var computerChoice = Math.random();
if (computerChoice<=0&&>= 0.33)
else if(computerChoice<=0.33&&>=0.66)


i too corrected the semicolons which i missed in the above code


So there are 2 main issues with your code, 1 would cause an error, the other would just give you an incorrect result.

  1. if(computerChoice<=0&&>=0.33) is invalid. you have to specify the variable again that line should look like this:
    if(computerChoice<=0 && computerChoice>=0.33)
    the else if statement will need to be fixed as well

  2. With the if and else if statements fixed your code should run but it will give you the wrong result
    let’s pretend computerChoice = 0.15
    if(computerChoice<=0 && computerChoice>=0.33) would be if(0.15<=0 && 0.15>=0.33)
    no number will ever pass that, it can’t be less than 0 and greater than 0.33, those operators need to be flipped.
    if(computerChoice >= 0 && computerChoice <=0.33)
    the same thing needs to be done to the else if statement


thanks sir for guiding me to take the correct code


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.