JSFiddle - React, Tailwind, and code Playground
HTML
<input type="button" value="Start count!" onclick="timedCount();" />
<input type="text" id="txt" />
JavaScript
var c = 0;
var t;
function timedCount() {
document.getElementById('txt').value = c;
c = c + 1;
if (c == 5) {
clearTimeout(t);
return false;
}
t = setTimeout(function () {
timedCount()
}, 1000);
}