JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<button id="do_the_magic">Find en vinder</button>
<div>Bord: <span id="table">?</span><img class="hideMe" id="tableLoading" src="https://cdnjs.cloudflare.com/ajax/libs/file-uploader/5.14.2/all.fine-uploader/loading.gif"></div>
<div>Plads: <span id="seat">?</span><img class="hideMe" id="seatLoading" src="https://cdnjs.cloudflare.com/ajax/libs/file-uploader/5.14.2/all.fine-uploader/loading.gif"></div>
CSS
.hideMe{
display:none;
}
JavaScript
var tables = {
'A': 28,
'B': 24,
'C': 28,
'D': 32,
'E': 32,
'F': 32,
'G': 32
}
$(function(){
$("#do_the_magic").click(function(){
//Show loader
$("#table").hide();
$("#seat").hide();
$("#tableLoading").show();
$("#seatLoading").show();
var keys = Object.keys(tables);
var table = keys[Math.floor(keys.length * Math.random())];
var seats = tables[table];
var seat = Math.floor(Math.random() * seats) + 1;
setTimeout(function(){
showWinner(table, seat);
}, 2000);
//$("#output").text(winner);
});
});
function showWinner(table, seat){
$("#tableLoading").hide();
$("#table").text(table).show();
setTimeout(function(){
showSeat(seat);
}, 2000);
}
function showSeat(seat){
$("#seatLoading").hide();
$("#seat").text(seat).show();
}