I have an integer value that I want to take from the initial value of 0 to 100 over the span of 10 seconds; However, I don’t want it to start from 0 and go instantly to 100 within that time-span, I want it to climb up to that value overtime, so from 0 to 1 to 2, etc. How could this effect be achieved?
>Solution :
You can use setInterval and update the value:
let value = 0;
let interval = setInterval(function () {
if(value >= 10) {
clearInterval(interval);
return
}
value++;
document.getElementById("value").innerHTML = value;
}, 1000);
<div id="value">0</div>