<!DOCTYPE html> <html> <head> <title>Age Calculator with fearless code 011</title> <style> #birth-date { font-size: 16px; padding: 5px 10px; border-radius: 3px; border: 1px solid #ccc; } #calculate { padding: 5px 10px; font-size: 16px; background: #2196F3; color: #fff; border: none; border-radius: 3px; } #calculate:hover { background: #1976D2; } #age { font-size: 16px; font-weight: bold; } .button { background-color: #f55a13; border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; } </style> </head> <body> <h1>Age Calculator</h1> <input type="date" id="birth-date"> <button id="calculate">Calculate</button> <p id="age"></p> <script> var calculateButton = document.getElementById('calculate'); var birthDate = document.getElementById('birth-date'); var age = document.getElementById('age'); calculateButton.onclick = function () { var today = new Date(); var birth = new Date(birthDate.value); var ageInMilliseconds = today - birth; var ageInYears = ageInMilliseconds / (1000 * 60 * 60 * 24 * 365.25); age.innerText = `You are ${Math.floor(ageInYears)} years old.`; } </script> </body> </html>
X