JSFiddle - React, Tailwind, and code Playground

by _abl

HTML

<span id="counter"></span>

<div id="console"></div>

JavaScript

function startCountDown(){
    
    var counter = 10;
    
    var interval = setInterval(function() {
        counter--;
        // Display 'counter' wherever you want to display it.
        document.getElementById("counter").innerHTML = "Timer:"+counter
        if (counter == 0) {
            // Submit form  
            out("Form submitted!");
            // Stop this interval so that it doesn't update the interface anymore (next interval will take care of that).
            clearInterval(interval);
            startCountDown();
        }
    }, 1000);
}
    
//startCountDown();

function out(msg){
    var p = document.createElement("P");
    p.appendChild(document.createTextNode(msg));
    document.getElementById("console").appendChild(p);
}