-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
43 lines (35 loc) · 1.23 KB
/
main.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
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const digitFormat = (digit) => `0${digit}`.slice(-2);
document.addEventListener('DOMContentLoaded', ()=>{
const timeUpdate = (time) => {
const seconds = document.getElementById('seconds');
const minutes = document.getElementById('minutes');
const hours = document.getElementById('hours');
const days = document.getElementById('days');
const qtdSeconds = time % 60;
const qtdMinutes = Math.floor((time % (60 * 60)) / 60);
const qtdHours = Math.floor((time % (60 * 60 * 24)) / (60 * 60));
const qtdDays = Math.floor(time / (60 * 60 * 24));
seconds.textContent = digitFormat(qtdSeconds);
minutes.textContent = digitFormat(qtdMinutes);
hours.textContent = digitFormat(qtdHours);
days.textContent = digitFormat(qtdDays);
}
const stopCounting = () => clearInterval(id);
const regressiveCountdown = (time) => {
const count = () => {
if(time === 0){
stopCounting();
}
timeUpdate (time)
time--;
}
const id = setInterval(count,1000);
}
const timeLeft = () => {
const eventDate = new Date ('2023-04-12 20:00:00');
const today = Date.now();
return Math.floor((eventDate - today) / 1000);
}
regressiveCountdown(timeLeft());
})