Last active
August 3, 2017 19:35
-
-
Save geopic/b4a820cdcc3b90442e81ad760428a57e to your computer and use it in GitHub Desktop.
Random-number-generation function, useful for luck-based code
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
function findChoice() { | |
// local var generating random number, then console.log() to check it works | |
var rng = Math.floor(Math.random() * 100); | |
console.log(rng); | |
// function determining action to take depending on range of number generated | |
function choice() { | |
if (rng <= 10) { | |
console.log('Below or equal to 10'); | |
} else if (rng > 10 && 20 >= rng) { | |
console.log('Above 10, up to 20'); | |
} else if (rng > 20 && 30 >= rng) { | |
console.log('Above 20, up to 30'); | |
} else if (rng > 30 && 40 >= rng) { | |
console.log('Above 30, up to 40'); | |
} else if (rng > 40 && 50 >= rng) { | |
console.log('Above 40, up to 50'); | |
} else if (rng > 50 && 60 >= rng) { | |
console.log('Above 50, up to 60'); | |
} else if (rng > 60 && 70 >= rng) { | |
console.log('Above 60, up to 70'); | |
} else if (rng > 70 && 80 >= rng) { | |
console.log('Above 70, up to 80'); | |
} else if (rng > 80 && 90 >= rng) { | |
console.log('Above 80, up to 90'); | |
} else if (rng > 90 && 100 >= rng) { | |
console.log('Above 90, up to 100'); | |
} | |
} choice(); | |
} | |
findChoice(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment