moze takie cos? https://codepen.io/JacekRojek/pen/BmrrLE
const count = document.querySelector(".count");
let sign = 1
setInterval(function(){
const oldValue = count.innerHTML
const newValue = parseInt(oldValue) + 1 * sign;
if(newValue > 100) {
sign = -1
} else if (newValue < 0){
sign = 1
}
count.innerHTML = parseInt(oldValue) + 1 * sign
}, 100);
albo tak:
const count = document.querySelector(".count");
loop = () => {
let x = 0
const interval = setInterval(() => {
x++
const newValue = 100 - Math.abs(x - 100)
count.innerHTML = newValue
if (newValue <= 0) {
clearInterval(interval)
loop()
}
}, 100);
}
loop()