function animateValue(id, start, end, duration) { const range = end - start; let current = start; const increment = end > start ? 1 : -1; const stepTime = Math.abs(Math.floor(duration / range)); const obj = document.getElementById(id); const timer = setInterval(function () { current += increment; obj.innerHTML = current; if (current === end) { clearInterval(timer); } }, stepTime); }