mirror of
https://github.com/dmuth/diceware.git
synced 2024-11-21 08:26:29 -05:00
First set of Javascript functions.
This commit is contained in:
parent
aa19cbd9b2
commit
2a6b70b203
2 changed files with 60 additions and 0 deletions
|
@ -112,5 +112,8 @@ For more information on Diceware:
|
|||
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
<!-- Include all compiled plugins (below), or include individual files as needed -->
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
|
||||
<script src="./main.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
57
main.js
Normal file
57
main.js
Normal file
|
@ -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);
|
||||
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
|
Loading…
Reference in a new issue