-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (27 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"use strict";
const countDate = new Date("march 15 2023 00:00:00").getTime();
const countDown = () => {
const now = new Date().getTime();
const countDownTime = countDate - now;
if (countDownTime <= 1000) {
document.querySelector(".text-time").style.display = "none";
document.querySelector(".expired").textContent = "TIME HAS EXPIRED!";
}
const second = 1000;
const minute = second * 60;
const hour = minute * 60;
const day = hour * 24;
let textDay = Math.floor(countDownTime / day);
let textHour = Math.floor((countDownTime % day) / hour);
let textMinute = Math.floor((countDownTime % hour) / minute);
let textSecond = Math.floor((countDownTime % minute) / second);
document.querySelector(".day").textContent =
textDay < 10 ? `0${textDay}` : `${textDay}`;
document.querySelector(".hour").textContent =
textHour < 10 ? `0${textHour}` : `${textHour}`;
document.querySelector(".minute").textContent =
textMinute < 10 ? `0${textMinute}` : `${textMinute}`;
document.querySelector(".second").textContent =
textSecond < 10 ? `0${textSecond}` : `${textSecond}`;
};
setInterval(countDown, 1000);