Skip to content

Instantly share code, notes, and snippets.

@abhi9bakshi
Last active July 20, 2018 05:29
Show Gist options
  • Save abhi9bakshi/eaa0d058d091d55d8dae9112f1e67615 to your computer and use it in GitHub Desktop.
Save abhi9bakshi/eaa0d058d091d55d8dae9112f1e67615 to your computer and use it in GitHub Desktop.
Simple Javascript Timer with Browser Hang Feature
// index.html
<p id="timer">
00:00:00
</p>
<button onClick="hangTheBrowser()">
Hang the browser
</button>
// 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);
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