Calculator Tools Calculator Tools
Create

Fun Age Calculator

Oct 8, 2023

About this app

A fun and colorful age calculator.

Fun Age Calculator 🎂 Fun Age Calculator 🎂 Calculate Age

Related apps

Put this on your site

Source

                    <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">

<title>Fun Age Calculator</title>
<meta name="description" content="A fun and colorful age calculator.">
<meta name="keywords" content="age, calculator, birthday">

<link href="https://fonts.googleapis.com/css2?family=Lobster&display=swap" rel="stylesheet">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<script type="text/javascript">
try {
function calculateAge() {
var birthdate = new Date(document.getElementById("birthdate").value);
var ageDifMs = Date.now() - birthdate.getTime();
var ageDate = new Date(ageDifMs);
return Math.abs(ageDate.getUTCFullYear() - 1970);
}

document.addEventListener("DOMContentLoaded", function() {
document.getElementById("calculate").addEventListener("click", function() {
document.getElementById("age").innerText = "Your age is " + calculateAge() + " 🎉";
});
});

} catch (error) {
throw error;
}
</script>

<style>
body {
background: linear-gradient(to right, #ff9966, #ff5e62);
color: white;
}
h1 {
font-family: 'Lobster', cursive;
text-align: center;
padding: 20px;
}
#main-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-direction: column;
}
#calculate {
margin-top: 10px;
}
#age {
margin-top: 20px;
font-size: 24px;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>🎂 Fun Age Calculator 🎂</h1>
<input type="date" id="birthdate" class="form-control">
<button id="calculate" class="btn btn-light">Calculate Age</button>
<p id="age"></p>
</div>
</body>
</html>