JSFiddle - React, Tailwind, and code Playground

by naryad

HTML

<button id="countButton">Count</button>
<span id="countLabel"></span>

JavaScript

//counter based on setTimeout illustration
var button = document.getElementById( 'countButton' ),
    label = document.getElementById( 'countLabel' );

button.onclick = function () {
    var n = 5;
    
    (function loop() {
        label.textContent = n;
        n -= 1;
        if ( n >= 0 ) {
            setTimeout( loop, 1000 );
        }
    })();
};