scrimba
Note at 2:55
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 2:55
AboutCommentsNotes
Note at 2:55
Expand for more info
index.js
run
preview
console
const countdownDisplay = document.getElementById("countdown-display");
const birthdayDisplay = document.getElementById("birthday-display")

function renderCountdown(element, targetDate) {
const now = new Date();
const remainingTime = targetDate - now;

const days = Math.floor(remainingTime / (1000 * 60 * 60 * 24));
const hours = Math.floor(remainingTime / (1000 * 60 * 60) % 24);
const minutes = Math.floor(remainingTime / (1000 * 60) % 60);
const seconds = Math.floor(remainingTime / 1000 % 60);

element.textContent = `${days}d ${hours}h ${minutes}m ${seconds}s`;
}

renderCountdown(countdownDisplay, new Date('2023-12-25'));
renderCountdown(birthdayDisplay, new Date('2023-12-12'));

setInterval(() => {
renderCountdown(countdownDisplay, new Date('2023-12-25'));
renderCountdown(birthdayDisplay, new Date('2023-12-12'));
}, 1000);
Console
/index.html
LIVE