JSFiddle - React, Tailwind, and code Playground

JavaScript

function foo() {
    if (typeof foo.counter == 'undefined') {
        foo.counter = 0;
    }
    alert("Run No. " + (++foo.counter));

    if (foo.counter < 5) {
        setTimeout(function() {
            foo(foo.counter + 1);
        }, 400);
    }

}

foo();