Created
June 7, 2017 01:56
-
-
Save stephenhmarsh/37b5aa96cfad788e87dbfd0474d0d780 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=37b5aa96cfad788e87dbfd0474d0d780
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> | |
<title>RaffleBot</title> | |
</head> | |
<body> | |
<div class="centered"> | |
<h1>RaffleBot</h1> | |
<button id="raffle" class="alert">Raffle Time!!!</button> | |
</div> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-3"> | |
<p>Tickets remaining: <span id="count"></span></p> | |
<p>Winners:</p> | |
<ul id="winners"> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
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
{"enabledLibraries":["jquery","bootstrap","mustache"],"hiddenUIComponents":["editor.css","editor.html"]} |
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
var students = { | |
"Eri" : 62, | |
"Jyraya" : 69, | |
"Jennifer" : 58, | |
"Jytia " : 57, | |
"Sanai" : 31, | |
"Dante" : 22, | |
"Lissete" : 19, | |
"Xavier" : 17, | |
"Layla" : 12, | |
"Jaevon" : 11, | |
"Maya" : 7, | |
"Aletha" : 1, | |
"Jhonny" : 0 | |
}; | |
var bowlOfTickets = []; | |
for (var studentName in students) { | |
var points = students[studentName]; | |
while(points > 0) { | |
bowlOfTickets.push(studentName); | |
points--; | |
} | |
} | |
function raffle(){ | |
var winner = bowlOfTickets.splice(random(), 1); | |
alert(winner); | |
updateStats(winner); | |
} | |
function random(){ | |
return Math.floor(Math.random() * bowlOfTickets.length); | |
} | |
function updateStats(winner){ | |
$('#count').html(bowlOfTickets.length); | |
if (!!winner) { | |
$('#winners').append('<li>' + winner + '</li>'); | |
} | |
} | |
$('#raffle').click(raffle); | |
updateStats(); |
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
body { | |
width: 100%; | |
height: 100%; | |
} | |
.centered { | |
text-align: center; | |
} | |
#raffle { | |
margin-top: 10px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment