JSFiddle - React, Tailwind, and code Playground

HTML

<input type="button" value=" Toggle Timer " />
<br/>
<div>0</div>

JavaScript

(function() {    
    var switcher;
    function count() {
        $("div").html(1 + parseInt($("div").html(), 10));
    }
    $(function() {
        switcher = setInterval(count, 1000);
        $("input").click(function() {
            $("div").toggle();
            if ($("div").is(":visible"))
            {
                switcher = setInterval(count, 1000);
            } else
            {
                clearInterval(switcher);            
            }
        });
    });
}());