FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-Projects/countdown-timer/script.js at main · shubh73/JavaScript-Projects · GitHub
shubh73
/
JavaScript-Projects
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
5
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-Projects
/
countdown-timer
/
script.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (24 loc) · 912 Bytes
Breadcrumbs
JavaScript-Projects
/
countdown-timer
/
script.js
Copy path
File metadata and controls
34 lines (24 loc) · 912 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
const
daysEl
=
document
.
getElementById
(
"days"
)
;
const
hoursEl
=
document
.
getElementById
(
"hours"
)
;
const
minsEl
=
document
.
getElementById
(
"mins"
)
;
const
secondsEl
=
document
.
getElementById
(
"seconds"
)
;
const
newYears
=
"1 Jan 2022"
;
function
countdown
(
)
{
const
newYearsDate
=
new
Date
(
newYears
)
;
const
currentDate
=
new
Date
(
)
;
const
totalSeconds
=
(
newYearsDate
-
currentDate
)
/
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
;
daysEl
.
innerHTML
=
days
;
hoursEl
.
innerHTML
=
formatTime
(
hours
)
;
minsEl
.
innerHTML
=
formatTime
(
mins
)
;
secondsEl
.
innerHTML
=
formatTime
(
seconds
)
;
}
function
formatTime
(
time
)
{
return
time
<
10
?
(
`0
${
time
}
`
)
:
time
;
}
//initial call
countdown
(
)
;
setInterval
(
countdown
,
1000
)
;
Back
|
FazBrowse Home
|
New Git URL