File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 " />
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
7
+ < link rel ="stylesheet " type ="text/css " href ="style.css " />
8
+ < title > Count-Down Timer</ title >
9
+ </ head >
10
+ < body >
11
+ < h1 > Count-Down Timer</ h1 >
12
+ < div class ="container ">
13
+ < input type ="datetime-local " id ="datetime-input " required />
14
+ < button id ="start-button "> Start</ button >
15
+ < div id ="timer "> </ div >
16
+ </ div >
17
+ < script src ="script.js "> </ script >
18
+ </ body >
19
+ </ html >
Original file line number Diff line number Diff line change
1
+ const datetimeInput = document . getElementById ( 'datetime-input' ) ;
2
+ const startButton = document . getElementById ( 'start-button' ) ;
3
+ const timerDisplay = document . getElementById ( 'timer' ) ;
4
+
5
+ function startCountdown ( ) {
6
+ const selectedDatetime = new Date ( datetimeInput . value ) . getTime ( ) ;
7
+
8
+ const countdownInterval = setInterval ( ( ) => {
9
+ const now = new Date ( ) . getTime ( ) ;
10
+ const distance = selectedDatetime - now ;
11
+
12
+ if ( distance < 0 ) {
13
+ clearInterval ( countdownInterval ) ;
14
+ timerDisplay . textContent = 'Countdown Over!' ;
15
+ } else {
16
+ const days = Math . floor ( distance / ( 1000 * 60 * 60 * 24 ) ) ;
17
+ const hours = Math . floor (
18
+ ( distance % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 )
19
+ ) ;
20
+ const minutes = Math . floor ( ( distance % ( 1000 * 60 * 60 ) ) / ( 1000 * 60 ) ) ;
21
+ const seconds = Math . floor ( ( distance % ( 1000 * 60 ) ) / 1000 ) ;
22
+
23
+ timerDisplay . textContent = `${ days } d ${ hours } h ${ minutes } m ${ seconds } s` ;
24
+ }
25
+ } , 1000 ) ;
26
+ }
27
+
28
+ startButton . addEventListener ( 'click' , startCountdown ) ;
Original file line number Diff line number Diff line change
1
+ body {
2
+ font-family : Arial, sans-serif;
3
+ text-align : center;
4
+ background-color : cyan;
5
+ text-shadow : 3px 3px 5px lime;
6
+ }
7
+
8
+ h1 {
9
+ margin-top : 200px ;
10
+ font-size : 50px ;
11
+ text-shadow : 3px 3px 5px lime;
12
+ }
13
+ .container {
14
+ margin-top : 50px ;
15
+ }
16
+
17
+ input ,
18
+ button {
19
+ padding : 10px ;
20
+ font-size : 30px ;
21
+ background-color : white;
22
+ border : none;
23
+ border-radius : 10px ;
24
+ box-shadow : 3px 3px 5px lime;
25
+ }
26
+
27
+ # timer {
28
+ font-size : 30px ;
29
+ margin-top : 200px ;
30
+ }
You can’t perform that action at this time.
0 commit comments