Countdown

by MD Hasan Patwary

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Time Travel Countdown</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="container">
        <h1>Time Travel Departure Countdown</h1>
        <div id="countdown"></div>
    </div>

    <script src="script.js"></script>
</body>
</html>

CSS

body {
    font-family: Arial, sans-serif;
    background-color: #0d0d0d;
    color: #fff;
    text-align: center;
}

.container {
    max-width: 600px;
    margin: 50px auto;
    padding: 20px;
    border: 2px solid #555;
    border-radius: 10px;
    background-color: #1a1a1a;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 30px;
}

#countdown {
    font-size: 3rem;
    font-weight: bold;
    padding: 20px;
    background-color: #333;
    border-radius: 10px;
    margin: 20px auto;
    width: 80%;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

JavaScript

// Target date for the countdown (replace with your desired date)
const targetDate = new Date('2024-12-31T23:59:59').getTime();

// Update the countdown every second
const countdown = setInterval(() => {
    const now = new Date().getTime();
    const distance = targetDate - now;

    // Calculating days, hours, minutes, seconds
    const days = Math.floor(distance / (1000 * 60 * 60 * 24));
    const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    const seconds = Math.floor((distance % (1000 * 60)) / 1000);

    // Display the countdown
    document.getElementById('countdown').innerHTML = `${days}d ${hours}h ${minutes}m ${seconds}s`;

    // When the countdown is over, display a message
    if (distance < 0) {
        clearInterval(countdown);
        document.getElementById('countdown').innerHTML = 'Time Machine Departed!';
    }
}, 1000);