My JavaScript timer is working bizarrely: it goes 3-2 and then abruptly it finishes (without going through step 1 and 0). Here is the code:
var count = 3;
function countDown() {
document.getElementById("count").innerHTML = count;
if (count > 0) {
count--
}
else {
clearInterval(ncount);
document.getElementById("count").style.display = "none"
}
var ncount = setInterval("countDown()", 1000);
}
<form id="askName">
<label> Enter your username: </label>
<input id="input" type="text" required maxlength="10">
<button type="button" onclick="countDown()"> Submit </button>
</form>
<h2 id="count"> </h2>
Why does this occur?