Skip to content

Instantly share code, notes, and snippets.

@kevmor11
Created April 4, 2017 19:13
Show Gist options
  • Save kevmor11/f1c05363a222e7ce945541d99091dcfe to your computer and use it in GitHub Desktop.
Save kevmor11/f1c05363a222e7ce945541d99091dcfe to your computer and use it in GitHub Desktop.
Rolls a variable number of dice based on a given integer argument
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