Burpee Prognosis
by Daniel Suess
HTML
<form action='javascript:console.log'>
<h1>
#10kBurpee2018 Rechner
</h1>
<label for='burpeeCount'>Meine Burpees bis heute</label>
<input id='burpeeCount' type='number' value='1505' />
<br/>
<br/>
<input id='calcButton' type='submit' value='Wann knacke ich die 10.000?' />
<br/>
<div id='resultBox'>
</div>
</form>
CSS
* {
font-family: sans-serif;
}
#resultBox {
margin-top: 1em;
}
#resultBox .date {
font-weight: bold;
}
JavaScript
'use strict';
var calcBtn = $('#calcButton'),
resultBox = $('#resultBox'),
burpeesDoneInput = $('#burpeeCount'),
MILLIS_PER_DAY = 1000 * 60 * 60 * 24,
BURPEES_GOAL = 10000;
function calculatePrognosis() {
var startDay = Date.parse('01 Jan 2018'),
daysPassed = Math.ceil((Date.now() - startDay) / MILLIS_PER_DAY, 0),
burpeesDone = burpeesDoneInput.val(),
avgBurpeesPerDay = Math.floor(burpeesDone / daysPassed, 0),
prognosisDaysToGo = Math.ceil((BURPEES_GOAL - burpeesDone) / avgBurpeesPerDay, 0),
prognosisDate = new Date(Date.now() + prognosisDaysToGo * MILLIS_PER_DAY);
resultBox.html('Du knackst die 10.000 Burpees am <span class="date">' + prognosisDate.getDate() + '.' + (prognosisDate.getMonth() + 1) + '.</span>, wenn du weiter machst wie bisher! :) ');
}
calcBtn.on('click', calculatePrognosis);