We all knows that age is just a number, But we often try to calculate our actual age, for that i have created a simple age calculator using javascript.

This is a simple calculator using vanilla javascript.

Function Description

form.addEventListener('submit', function(event) {
    event.preventDefault();
}

An event listener and preventDefault to prevent it redirect to any other page.

 var birthyear = Number.parseFloat(byear.value),
        birthmonth = Number.parseFloat(bmonth.value),
        birthday = Number.parseFloat(bdate.value),
        todayyear = Number.parseFloat(year.value),
        todaymonth = Number.parseFloat(month.value),
        todays = Number.parseFloat(date.value);

values being set to these variable.

 if (todays < birthday) {
        days.innerHTML = (todays - birthday + 30) + ' days';
        todaymonth = todaymonth - 1;
    } else {
        days.innerHTML = (todays - birthday) + ' days'
    }

    if (todaymonth < birthmonth) {
        months.innerHTML = (todaymonth - birthmonth + 12) + ' months';
        todayyear = todayyear - 1;
    } else {
        months.innerHTML = (todaymonth - birthmonth) + ' months'
    }

    age.innerHTML = "Age: " + (todayyear - birthyear) + ' years';


Using if else i have just performed some arithmetic operations to calculate the age.

hope you like this,