Skip to content

Instantly share code, notes, and snippets.

@ferdousulhaque
Created August 2, 2020 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferdousulhaque/6aa1bea32837939f86bf7fcac35c7b0e to your computer and use it in GitHub Desktop.
Save ferdousulhaque/6aa1bea32837939f86bf7fcac35c7b0e to your computer and use it in GitHub Desktop.
JS Timer
//require('./bootstrap');
let timerOn = true;
function timer(remaining) {
var m = Math.floor(remaining / 60);
var s = remaining % 60;
m = m < 10 ? '0' + m : m;
s = s < 10 ? '0' + s : s;
document.getElementById('timer').innerHTML = m + ':' + s;
remaining -= 1;
if(remaining >= 0 && timerOn) {
setTimeout(function() {
timer(remaining);
}, 1000);
return;
}
if(!timerOn) {
// Do validate stuff here
return;
}
// Do timeout stuff here
alert('Timeout for otp');
}
timer(120);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment