-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (45 loc) · 1.69 KB
/
Copy pathapp.js
File metadata and controls
51 lines (45 loc) · 1.69 KB
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
44
45
46
47
48
49
50
51
const dateInput = document.querySelector('.date-box');
const submitButton = document.querySelector('.sub-but');
submitButton.clickCount = 0;
submitButton.addEventListener("click", getReqDate);
function getReqDate(event) {
if (++this.clickCount === 2) {
location.reload();
}
const reqTime = dateInput.value;
if (reqTime == '') {
alert("Enter A Date!");
location.reload();
}
const reqTimeDate = new Date(reqTime);
let currentDate = new Date();
if (isNaN(reqTimeDate)) {
alert("Enter The Date Like In Example");
location.reload();
}
if (reqTimeDate < currentDate) {
alert("Enter A Future Date!");
location.reload();
}
function countdown() {
currentDate = new Date();
const heading = document.querySelector('.heading');
const daysItem = document.getElementById('big-text-day');
const hoursItem = document.getElementById('big-text-hour');
const minutesItem = document.getElementById('big-text-minute');
const secondsItem = document.getElementById('big-text-second');
const diff = (reqTimeDate - currentDate);
const totalseconds = diff / 1000;
const days = Math.floor(totalseconds / 3600 / 24);
const hours = Math.floor((totalseconds / 3600) % 24);
const mins = Math.floor((totalseconds / 60) % 60);
const seconds = Math.floor(totalseconds % 60);
daysItem.innerHTML = days;
hoursItem.innerHTML = hours;
minutesItem.innerHTML = mins;
secondsItem.innerHTML = seconds;
heading.innerHTML = "Time Until " + reqTime;
console.log(currentDate);
}
setInterval(countdown, 1000);
}