Skip to content

Dhivyaa12/CodeAlpha

Repository files navigation

HTML CODE

<title>Age Calculator</title>

Age Calculator

Day:
Month:
Year:
Calculate Age

<script src="ageCalculator.js"></script>

JAVASCRIPT CODE function calculateAge() { const day = parseInt(document.getElementById('day').value); const month = parseInt(document.getElementById('month').value); const year = parseInt(document.getElementById('year').value);

const today = new Date();
const birthDate = new Date(year, month - 1, day);

let age = today.getFullYear() - birthDate.getFullYear();
const monthDifference = today.getMonth() - birthDate.getMonth();

if (monthDifference < 0 || (monthDifference === 0 && today.getDate() < birthDate.getDate())) {
    age--;
}

document.getElementById('result').innerText = `Your age is ${age} years old.`;

}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published