Rock, paper, scissors: if, else if, else: please help


#1

Hi i just started learning and i have a problem, could you please tell me why "rock" remains the only option picked by the computer?


var userChoice = prompt("what do you want to pick? rock, paper or scissors")
console.log("you choose"+" "+userChoice)

var computerChoice=Math.random();
console.log(computerChoice);

if (computerChoice < 0,34) 
{
    console.log("the computer choose rock!");
    computerChoice="rock";
    }
    
else if (computerChoice > 0,67)
{
    console.log("the computer choose scissors!");
    computerChoice="scissors";
    }
else {
    console.log("the computer choose paper!");
    computerChoice="paper";
    };

#2

Hi try to change how you wrote the number like that

0,33 to 0.33

0,66 to 0.67

With a dot.


#3

@wizmarco is right. Unfortunately , is not a different decimal point but an operator that chains 2 statements where the latter one produces the output so in your case (a,b has a value of b):

a: computerChoice < 0
b: 34

And as you can read here:
http://www.sitepoint.com/javascript-truthy-falsy/
all values not being 0 are treated as truthy, that's why you always pick rock.


#4

thanks @wizmarco @haxor789