+ 1
How to get random variables in JavaScript?
Suppose I make two variables and when I log it in Console then it should have one random variables out of those two Please Help
3 RĂ©ponses
+ 10
Éá§Ï
ê±ÉŠ you can use Math.random() function
+ 5
As Sakshi said, use Math.random();
To solve your problem of "picking between two variables.", We can use partial probability of Math.random()
Math.random() --> always gives 0.something
We can do something like this
if(Math.random() > 0.5)
Use variable 1
else
Use variable 2
+ 4
Morpheus thanks for explaining it out