From 2a6b70b20313961bc45ff6761b5f4bd49d9bf227 Mon Sep 17 00:00:00 2001 From: Douglas Muth Date: Sat, 25 Apr 2015 23:02:05 -0400 Subject: [PATCH] First set of Javascript functions. --- index.html | 3 +++ main.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 main.js diff --git a/index.html b/index.html index 7710780..a2d3201 100644 --- a/index.html +++ b/index.html @@ -112,5 +112,8 @@ For more information on Diceware: + + + diff --git a/main.js b/main.js new file mode 100644 index 0000000..b4407c8 --- /dev/null +++ b/main.js @@ -0,0 +1,57 @@ +/** +* Our main Javascript file. +*/ +(function() { + +/** +* Roll a die. +* +* @return integer A random number between 1 and 6, inclusive. +*/ +function die_roll() { + return(Math.floor(Math.random() * 6) + 1); +} + + +/** +* Roll a die n times. +* +* @return integer a 5-digit integer representing 5 dice rolls. +*/ +function roll_dice() { + var retval = + String(die_roll()) + String(die_roll()) + + String(die_roll()) + String(die_roll()) + + String(die_roll()) + ; + retval = parseInt(retval); + return(retval); +} + + +/** +* Look up a word from our wordlist. +* +* @param object wordlist Our hash table of dice rolls and their corresponding words. +* @param integer index +* +* @return string The word from the dicelist +*/ +function get_word(wordlist, index) { + var retval = wordlist[index]; + return(retval); +} + + +jQuery.getScript("./wordlist.js").done( + function(data) { + + }).fail( + function(jqxhr, settings, exception) { + console.log("Error loading Javascript:", jqxhr.status, settings, exception); + + }); + +})(); + +