JSFiddle - React, Tailwind, and code Playground

HTML

<input type="hidden" id="counter" value="1" />

JavaScript

function foo() {
    var counter = document.getElementById('counter');
    var counterValue = parseInt(counter.value, 10);
    alert('Run No. ' + counterValue);
    if (counterValue < 5) {
        counter.value = counterValue + 1;
        window.setTimeout(foo, 400);
    }
}

foo();