-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
28 lines (26 loc) · 916 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function age() {
var dateOne = document.getElementById("date").value;
var monthOne = document.getElementById("month").value;
var yearOne = document.getElementById("year").value;
var date = new Date();
var dateTwo = date.getDate();
var monthTwo = date.getMonth();
var yearTwo = date.getFullYear();
var month = [31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31];
if(dateOne.length && monthOne.length && yearOne.length > 0){
if (dateOne > dateTwo) {
dateTwo = dateTwo + month[monthTwo - 1];
monthTwo = monthTwo - 1;
}
if (monthOne > monthTwo) {
monthTwo = monthTwo + 13;
yearTwo = yearTwo - 1;
}
var d = dateTwo - dateOne;
var m = monthTwo - monthOne;
var y = yearTwo - yearOne;
document.getElementById(
"age"
).innerHTML = `Your Age is "${y}" Years "${m}" Months "${d}" Days"`;
}
}