Last active
July 20, 2018 05:30
-
-
Save abhi9bakshi/564cea231066cc7079c1c8f83fcaa5b2 to your computer and use it in GitHub Desktop.
Javascript Timer using Date method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.html | |
<p id="timer"> | |
00:00:00 | |
</p> | |
<button onClick="hangTheBrowser()"> | |
Hang the browser | |
</button> | |
// script.js | |
let start = new Date(); | |
let intervalRef = null; | |
intervalRef = setInterval(_ => { | |
let current = new Date(); | |
let count = +current - +start; | |
let ms = count % 1000; | |
let s = Math.floor((count / 1000)) % 60; | |
let m = Math.floor((count / 60000)) % 60; | |
$('#timer').text(m + ":" + s + ":" + ms); | |
}, 10); | |
function hangTheBrowser() { | |
let val = ""; | |
for(let i=0; i<10000; i++){ | |
for(let j=0; j<10000; j++) { | |
val = "Loop returned: " + i + j; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment