Skip to content

Instantly share code, notes, and snippets.

@Nephos
Created March 23, 2016 00:35
Show Gist options
  • Save Nephos/d25951063a15b4ef93e3 to your computer and use it in GitHub Desktop.
Save Nephos/d25951063a15b4ef93e3 to your computer and use it in GitHub Desktop.
Coding Academy Countdown
<html>
<body style="background: black;">
<h1 id="countdown" style='color: red; text-align: center; font-family: "Monospace"; font-size: 12em; margin: 20%;'></h1>
<script>
let endTime = new Date((new Date()).toDateString() + " 21:00:00");
let currTime = new Date();
let endInt = endTime.getTime();
let currInt = currTime.getTime();
function updateCounter() {
currTime = new Date();
endInt = endTime.getTime();
currInt = currTime.getTime();
var duration = endInt - currInt;
var durationTime = new Date(duration)
var seconds = durationTime.getSeconds() + ""; if (seconds.length == 1) { seconds = "0" + seconds; }
var minutes = durationTime.getMinutes() + ""; if (minutes.length == 1) { minutes = "0" + minutes; }
var hours = durationTime.getHours() - 1 + ""; if (hours.length == 1) { hours = "0" + hours; }
var counter = hours + ":" + minutes + ":" + seconds;
console.log(counter);
document.getElementById("countdown").innerHTML = counter;
if (endInt > currInt ) {
setTimeout(updateCounter, 1000);
} else {
document.getElementById("countdown").innerHTML = "MOULINETTE IS COMMING."
}
}
setTimeout(updateCounter, 1000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment