|
1 |
| -<script> |
2 |
| - // Set the date we're counting down to |
3 |
| - var countDownDate = new Date().getTime() + 20 * 60 * 1000; // 20 minutes from now |
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>Countdown Timer</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + display: flex; |
| 10 | + justify-content: center; |
| 11 | + align-items: center; |
| 12 | + height: 100vh; |
| 13 | + font-family: Arial, sans-serif; |
| 14 | + } |
| 15 | + #countdown { |
| 16 | + font-size: 48px; |
| 17 | + } |
| 18 | + </style> |
| 19 | +</head> |
| 20 | +<body> |
| 21 | + <div id="countdown">10:00</div> |
| 22 | + <script> |
| 23 | + // Set the date we're counting down to |
| 24 | + var countDownDate = new Date().getTime() + 20 * 60 * 1000; // 10 minutes from now |
4 | 25 |
|
5 |
| - // Update the count down every 1 second |
6 |
| - var x = setInterval(function() { |
7 |
| - // Get today's date and time |
8 |
| - var now = new Date().getTime(); |
9 |
| - |
10 |
| - // Find the distance between now and the count down date |
11 |
| - var distance = countDownDate - now; |
| 26 | + // Update the count down every 1 second |
| 27 | + var x = setInterval(function() { |
| 28 | + // Get today's date and time |
| 29 | + var now = new Date().getTime(); |
| 30 | + |
| 31 | + // Find the distance between now and the count down date |
| 32 | + var distance = countDownDate - now; |
12 | 33 |
|
13 |
| - // Time calculations for minutes and seconds |
14 |
| - var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); |
15 |
| - var seconds = Math.floor((distance % (1000 * 60)) / 1000); |
| 34 | + // Time calculations for minutes and seconds |
| 35 | + var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); |
| 36 | + var seconds = Math.floor((distance % (1000 * 60)) / 1000); |
16 | 37 |
|
17 |
| - // Display the result in the element with id="countdown" |
18 |
| - document.getElementById("countdown").innerHTML = minutes + ":" + (seconds < 10 ? "0" : "") + seconds; |
| 38 | + // Display the result in the element with id="countdown" |
| 39 | + document.getElementById("countdown").innerHTML = minutes + ":" + (seconds < 10 ? "0" : "") + seconds; |
19 | 40 |
|
20 |
| - // If the count down is finished, write some text |
21 |
| - if (distance < 0) { |
22 |
| - clearInterval(x); |
23 |
| - document.getElementById("countdown").innerHTML = "TIME'S UP!"; |
24 |
| - } |
25 |
| - }, 1000); |
26 |
| -</script> |
| 41 | + // If the count down is finished, write some text |
| 42 | + if (distance < 0) { |
| 43 | + clearInterval(x); |
| 44 | + document.getElementById("countdown").innerHTML = "TIME'S UP!"; |
| 45 | + } |
| 46 | + }, 1000); |
| 47 | + </script> |
| 48 | +</body> |
| 49 | +</html> |
0 commit comments