Skip to content

Instantly share code, notes, and snippets.

@PrimeTimeTran
Last active May 18, 2019 02:04
Show Gist options
  • Save PrimeTimeTran/fb464d174fbf57ee8868140d0e5d7c1b to your computer and use it in GitHub Desktop.
Save PrimeTimeTran/fb464d174fbf57ee8868140d0e5d7c1b to your computer and use it in GitHub Desktop.
// 1. Get total number of dice to be rolled.
const numberOfDice = Math.floor((Math.random() * 20))
numberOfDice // What am I?
// 2. Variables to store dice rolls sum & individual rolls.
let diceSum = 0
let diceRolls = []
// 3. Number of dice choosen roll a random num 1-6.
for(var i = 0; i < numberOfDice; i++){
let diceRoll = Math.floor((Math.random() * 6)) + 1
// Add to diceRolls array
diceRolls.push(diceRoll)
// Add to sum
diceSum += diceRoll
}
// What are we?
diceRolls
diceSum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment