scrimba
Note at 1:49
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 1:49
AboutCommentsNotes
Note at 1:49
Expand for more info
index.js
run
preview
console
// Task:
// - Get today's date (you only need the day).
// - Calculate remaining days.
// - Display remaining days in countdownDisplay.

function renderCountdown() {
// const christhmas = 25;
let christmas = new Date("12/24/2021 00:00:00");
let christmasInMill = christmas.getTime();
console.log("christmas in milliseconds is always: " + christmasInMill);

const currentDate = new Date();
let currentTimeInMill = currentDate.getTime();
console.log("current time is: " + currentTimeInMill)

let timeTillXmasInMill = (christmasInMill - currentTimeInMill);

console.log("time till xmas in milliseconds is: " + timeTillXmasInMill);
let result = Math.round(timeTillXmasInMill / 86400000); //86400000 milliseconds in a day to get the nr of days
console.log("time till xmas in days is: " + result);
return result;
}

let countdownDaysDisplay = document.getElementById("countdown-days-display");
countdownDaysDisplay.innerHTML = renderCountdown();

Console
"christmas in milliseconds is always: 1640332800000"
,
"current time is: 1638835801970"
,
"time till xmas in milliseconds is: 1496998030"
,
"time till xmas in days is: 17"
,
/index.html
LIVE