document.addEventListener("DOMContentLoaded", function () {
  function animateCount(elementId, start, end, duration) {
    var element = document.getElementById(elementId);
    var startTime = null;

    if (!element) {
      return;
    }

    function step(timestamp) {
      var progress;
      var value;

      if (!startTime) {
        startTime = timestamp;
      }

      progress = Math.min((timestamp - startTime) / duration, 1);
      value = Math.floor(start + (end - start) * progress);
      element.textContent = value.toString();

      if (progress < 1) {
        window.requestAnimationFrame(step);
      }
    }

    window.requestAnimationFrame(step);
  }

  animateCount("count", 10, 500, 1200);
  animateCount("projects", 40, 800, 1400);
});
