Untitled
unknown
plain_text
a year ago
610 B
7
Indexable
const input = document.getElementById('input');
const button = document.getElementById('button');
const ans = document.getElementById('ans');
button.addEventListener('click', function(){
const birthdate = new Date(input.value);
if(birthdate){
const today = new Date();
var age = today.getFullYear() - birthdate.getFullYear();
var month = today.getMonth() - birthdate.getMonth();
var date = today.getDate() - birthdate.getDate();
if(month < 0 || (month === 0 && date < 0 )){
age--;
}
ans.innerHTML = age;
}
}); Editor is loading...
Leave a Comment