Simple Countdown JS Script

    const deadline = new Date(Date.now() + 1000 * 60 * 60 * 24);

    function updateCountdown() {
      const now = new Date();
      const diff = deadline - now;
      let h = Math.floor(diff / (1000 * 60 * 60));
      let m = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
      let s = Math.floor((diff % (1000 * 60)) / 1000);

      if (diff <= 0) {
        h = m = s = 0;
      }

      document.getElementById('hours').textContent = String(h).padStart(2, '0');
      document.getElementById('minutes').textContent = String(m).padStart(2, '0');
      document.getElementById('seconds').textContent = String(s).padStart(2, '0');
    }

    updateCountdown();
    setInterval(updateCountdown, 1000);

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *