JSFiddle - React, Tailwind, and code Playground

by Shobhit Sharma

HTML

<body>
    <h1>For Stackoverflow question</h1>
    <input type="submit" value="Run Function" onclick="listMaker()" />
    <p style="color:red;"> Why doesn't it print each number one at a time??</p>
    <h2>List:</h2>
    
    <ul id="list">
    </ul>
</body>

JavaScript

var listMaker = function() {
    var list = document.getElementById('list'),
        i = 1;
    function doNext() {
        if (i < 150){
            list.innerHTML += "<li>" + i + "</li>";
            setTimeout(doNext, 100);
            i++;
        }
    }
    doNext();
};