Created
August 2, 2020 15:33
-
-
Save ferdousulhaque/6aa1bea32837939f86bf7fcac35c7b0e to your computer and use it in GitHub Desktop.
JS Timer
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
//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