Created
November 11, 2013 14:26
-
-
Save toymachiner62/7413916 to your computer and use it in GitHub Desktop.
This is a Fantasy Football draft order randomizer. This app that takes an array of names and displays them in a random order every time the page is refreshed.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.10.2.js"></script> | |
<script> | |
$(document).ready(function() { | |
var players = new Array("Tom", "Kraig", "PT", "Chanse", "Young", "Grant", "Paul", "JJ", "Ty", "Jason"); | |
var draftOrder = shuffle(players); | |
for(var index in draftOrder) { | |
$('#order').append('<li>#' + ++index + " " + draftOrder[--index] + '</li>'); | |
} | |
}); | |
// Shuffles an array and returns the output | |
function shuffle(array) { | |
var counter = array.length, temp, index; | |
// While there are elements in the array | |
while (counter > 0) { | |
// Pick a random index | |
index = Math.floor(Math.random() * counter); | |
// Decrease counter by 1 | |
counter--; | |
// And swap the last element with it | |
temp = array[counter]; | |
array[counter] = array[index]; | |
array[index] = temp; | |
} | |
return array; | |
} | |
</script> | |
</head> | |
<body> | |
<ul id="order"> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment