Created
April 4, 2017 19:13
-
-
Save kevmor11/f1c05363a222e7ce945541d99091dcfe to your computer and use it in GitHub Desktop.
Rolls a variable number of dice based on a given integer argument
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 rollDice (rolls) { | |
var result = "Rolled " + rolls + " dice: " | |
for (var i = 0; i < rolls; i++) { | |
var rollNum = Math.floor((Math.random(rolls)*6)+1); | |
if (i < rolls - 1) | |
result += (rollNum + ", "); | |
else | |
result += rollNum + "."; | |
} | |
return result; | |
}; | |
console.log(rollDice(process.argv[2])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment