+ 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

7th Apr 2023, 3:06 PM
ɑყυꜱɊ
ɑყυꜱɊ - avatar
3 RĂ©ponses
+ 10
ɑყυꜱɊ you can use Math.random() function
7th Apr 2023, 3:13 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 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
7th Apr 2023, 3:25 PM
Morpheus
Morpheus - avatar
+ 4
Morpheus thanks for explaining it out
7th Apr 2023, 3:28 PM
ɑყυꜱɊ
ɑყυꜱɊ - avatar