JSFiddle - React, Tailwind, and code Playground

HTML

<script src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/ui-lightness/jquery-ui.css">
Click here to begin<br>

JavaScript

var window_focus;
var counter = 1000;

$(window).focus(function() {
    window_focus = true;
});

$(window).focusout(function() {
    window_focus = false;
});
    

$(document).one('click',function() {
    setInterval(function() { 
        $('body').append('Count: ' + counter + '<br>'); 
        if(window_focus) { counter = counter-1; }
    }, 1000);
});