Last active
April 17, 2020 02:16
-
-
Save RPDeshaies/501cdc2f3d6b9e8b2afd546f0a30e232 to your computer and use it in GitHub Desktop.
Google Slides Fudge Dice
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 onOpen() { | |
SlidesApp.getUi() | |
.createMenu("Dice") | |
.addItem("Roll 4df", "runFudgeDice") | |
.addToUi(); | |
update(); | |
} | |
function runFudgeDice() { | |
const fudgeDice = [-1, -1, 0, 0, 1, 1]; | |
const result = rollDice(fudgeDice, 4); | |
const ui = SlidesApp.getUi(); | |
const title = "You rolled a " + result.toString(); | |
ui.alert(title, "", ui.ButtonSet.OK); | |
} | |
function rollDice(dice, times) { | |
let total = 0; | |
for (let i = 0; i < times; i++) { | |
const side = getRandomDiceSide(dice.length); | |
const roll = dice[side]; | |
total += roll; | |
} | |
return total; | |
} | |
function getRandomDiceSide(numberOfSides) { | |
const randomNumber = Math.round(Math.random() * 100); | |
const side = randomNumber % numberOfSides; | |
return side; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment