Age Calculator
body {
font-family: Arial, sans-serif;
}
.container {
max-width: 500px;
margin: 0 auto;
text-align: center;
}
form {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 1rem;
}
.form-group {
display: flex;
flex-direction: column;
align-items: flex-start;
margin-bottom: 1rem;
}
label {
margin-bottom: 0.5rem;
}
input {
padding: 0.5rem;
border: 1px solid #ccc;
border-radius: 0.25rem;
}
button {
padding: 0.5rem;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 0.25rem;
cursor: pointer;
}
#result {
font-size: 2rem;
font-weight: bold;
margin-top: 1rem;
}
function calculateAge() {
const birthdate = new Date(document.getElementById("birthdate").value);
const today = new Date();
const ageInMilliseconds = today - birthdate;
const ageInYears = ageInMilliseconds / (365 * 24 * 60 * 60 * 1000);
const age = Math.floor(ageInYears);
const result = document.getElementById("result");
result.innerHTML = `Your age is ${age} years.`;
}
Comments
Post a Comment