Skip to content

Instantly share code, notes, and snippets.

@abhi9bakshi
Last active July 20, 2018 05:30
Show Gist options
  • Save abhi9bakshi/039bb1af33d4249a6c0f1491d52cb11c to your computer and use it in GitHub Desktop.
Save abhi9bakshi/039bb1af33d4249a6c0f1491d52cb11c to your computer and use it in GitHub Desktop.
Simple Javascript countdown timer
// index.html
<p id="timer">
00:00:00
</p>
// script.js
let count = 0;
let intervalRef = null;
intervalRef = setInterval(_ => {
count+=10;
let ms = count % 1000;
let s = Math.floor((count / 1000)) % 60;
let m = Math.floor((count / 60000)) % 60;
$('#timer').text(m + ":" + s + ":" + ms);
}, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment