JSFiddle - React, Tailwind, and code Playground

JavaScript

for (x = 0; x < 10; x++) {

    if (moment(now) > moment(then)) {

        doIt(x); // do it now

    } else {

        timeTillEnd = moment(then) - moment(now);

        setTimeout(function () {

            doIt(x); // do it later

        }, timeTillEnd); // <-- flagged here

    }
}