HTML AND CSS CODES

ETHINGS
0

         


AGE CALCULATOR

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Age Calculator</title>
<style>
    body {
        font-family: Arial, sans-serif;
        background-color: #f8f4f4;
        margin: 0;
        padding: 0;
    }
    .wrapper {
        max-width: 390px;
        margin: 48px auto;
        background-color: #fff;
        padding: 20px;
        border-radius: 8px;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    }
    h1 {
        text-align: center;
    }
    label {
        display: block;
        margin-bottom: 10px;
    }
    input[type="text"] {
        width: calc(100% - 20px);
        padding: 10px;
        margin-bottom: 20px;
        border: 1px solid #ccc;
        border-radius: 4px;
        border-radius: 5px;
    }
    input[type="submit"] {
        width: 100%;
        padding: 10px;
        border: none;
        background-color: #010d1a;
        color: #fff;
        border-radius: 5px;
        cursor: pointer;
    }
    input[type="submit"]:hover {
        background-color: #14c014;
    }
    .result {
        margin-top: 20px;
        text-align: center;
        font-size: 18px;
    }
</style>
</head>
<body>

<div class="wrapper">
    <h1>Age Calculator</h1>
    <form id="ageCalculatorForm">
        <label for="birthYear">Enter your birth year:</label>
        <input type="text" id="birthYear" name="birthYear" placeholder="e.g., 1990" required>
        <input type="submit" value="Calculate">
    </form>
    <div class="result" id="result"></div>
</div>

<script>
    document.getElementById('ageCalculatorForm').addEventListener('submit', function(e) {
        e.preventDefault();
        var birthYear = document.getElementById('birthYear').value;
        var currentYear = new Date().getFullYear();
        var age = currentYear - birthYear;
        document.getElementById('result').innerText = "Your age is: " + age;
    });
</script>

</body>
</html>

                  

                                                      DIGITAL CLOCK             


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Clock</title>
<style>
    body {
        font-family: Arial, sans-serif;
        background-color: hsl(0, 0%, 13%);
        color: #0a0101;
        text-align: center;
        margin: 0;
        padding: 0;
    }
    .clock {
        font-size: 48px;
        margin-top: 100px;
        background-color: rgb(245, 246, 242);
        width: 250px;
        padding: 100px;
        justify-content: center;
        display: flex;
        align-items: center;
    }
</style>
</head>
<body>

<div class="clock" id="clock"></div>

<script>
    function updateClock() {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();

        // Add leading zeros to minutes and seconds if they are less than 10
        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        // Determine AM or PM suffix based on the hour
        var meridiem = hours >= 12 ? "PM" : "AM";

        // Convert the hour to 12-hour format if needed
        hours = hours > 12 ? hours - 12 : hours;

        // Display the time in HH:MM:SS format
        var timeString = hours + ":" + minutes + ":" + seconds + " " + meridiem;

        // Update the clock element's text
        document.getElementById("clock").textContent = timeString;
    }

    // Update the clock every second
    setInterval(updateClock, 1000);

    // Initial call to display the clock immediately
    updateClock();
</script>

</body>
</html>

Tags

Post a Comment

0Comments

Post a Comment (0)