JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
JavaScript
timer = 1000;
started = false;
$(document).keyup( function(){
window.timer = 1000;
if(window.started == false) queueTimer();
window.started = true;
});
function queueTimer(){
if(window.timer <= 0){
//Timer has run out, business logic here!
$('body').append('<strong>Timer out!</strong>');
window.started = false;
} else {
window.timer -= 100;
$('body').append(timer + "<br>");
setTimeout(queueTimer, 100);
}
}