+ 3
How can I make a function that happen depends on chances......
how can I make a function that will only happens with a chance of 50 %
1 Antwort
+ 14
Use Math.floor() and Math.random() to generate a 0 or 1, and if it's 0, run the code.
var num = Math.floor(Math.random() * 2)
if (num === 0)
{
//your code
}
//else nothing happens when the function is called