Last active
September 10, 2018 20:16
-
-
Save dreamyguy/4d9b6b920fbb2290a2fa258befe35dbc to your computer and use it in GitHub Desktop.
Chance + probability = possibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calculate chance | |
const chance = (percentage) => { | |
const probability = (percentage / 100); | |
return (Math.random() < probability ? 1 : 0); | |
}; | |
// Set percentage of possibility (10 = 10%, 75 = 75%) | |
const possibility = chance(70); | |
// Only execute it if 'possibility' is truthy | |
if (possibility) { | |
// It's possible! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment