-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
31 lines (24 loc) · 978 Bytes
/
script.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
var date = '21 February 2022';
const daysE = document.getElementById('days');
const hoursE = document.getElementById('hours');
const minsE = document.getElementById('minutes');
const secsE = document.getElementById('seconds');
const headingE = document.getElementById('heading');
function countdown(){
const countdownDay = new Date(date);
const today = new Date();
const totalMSeconds = (countdownDay - today);
const totalSeconds = totalMSeconds / 1000;
const days = Math.floor((totalSeconds / 3600) / 24);
const hours = Math.floor((totalSeconds / 3600) % 24);
const mins = Math.floor((totalSeconds / 60) % 60);
const secs = Math.floor(totalSeconds % 60);
daysE.innerHTML = days;
hoursE.innerHTML = hours;
minsE.innerHTML = mins;
secsE.innerHTML = secs;
}
const input = prompt("Enter the date you want to count down to in the form Day Month Year EG: 17 April 2021");
date = input;
countdown();
setInterval(countdown, 1000);