Chance for something to happen?
In my code, I would like to add something such as crit-chance (Critical Chance) and miss-chance (Your chance of missing). Is there a way I can implement that in my code, and be able to change the percentage later in my code?
let critChanceProbability = 5; // 5% chance let missChanceProbability = 10; // 10% chance if (Math.random() * 100 + 1 == critChanceProbability) // just got a crit! if (Math.random() * 100 + 1 == missChanceProbability) // just got a miss!
Assign x to anything you would like.
Remember that if you choose 10, it'll return a random number between 0-9, not 10. You can fix this by changing x to 11 or adding 1.