/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var roll = { d4 : function() { return Math.floor(Math.random() * (4 - 1 + 1)) + 1; }, d6 : function() { return Math.floor(Math.random() * (6 - 1 + 1)) + 1; }, d8 : function() { return Math.floor(Math.random() * (8 - 1 + 1)) + 1; }, d10 : function() { return Math.floor(Math.random() * (10 - 1 + 1)) + 1; }, d12 : function() { return Math.floor(Math.random() * (12 - 1 + 1)) + 1; }, d20 : function() { return Math.floor(Math.random() * (20 - 1 + 1)) + 1; } }; console.log("rolling D4 : " + roll.d4()); console.log("rolling D20 : " + roll.d20());