Skip to content

Instantly share code, notes, and snippets.

@stephenhmarsh
Created June 5, 2017 18:07
Show Gist options
  • Save stephenhmarsh/3aea427de60c55317ee701819250fd9b to your computer and use it in GitHub Desktop.
Save stephenhmarsh/3aea427de60c55317ee701819250fd9b to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=3aea427de60c55317ee701819250fd9b
<!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>
{"enabledLibraries":["jquery","bootstrap","mustache"],"hiddenUIComponents":["editor.css","editor.javascript","editor.html"]}
var students = {
"Eri" : 60,
"Jyraya" : 58,
"Jennifer" : 57,
"Jytia " : 55,
"Sanai" : 30,
"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();
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