-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (28 loc) · 1.08 KB
/
script.js
File metadata and controls
40 lines (28 loc) · 1.08 KB
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
29
30
31
32
33
34
35
36
37
38
39
function displayAge(){
const userDate = document.getElementById("day").value;
const userMonth = document.getElementById("month").value;
const userYear = document.getElementById("year").value;
const now = new Date();
let currentdate = now.getDate();
let currentMonth = now.getMonth() + 1;
let currentYear = now.getFullYear();
const monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if(userDate > currentdate){
currentdate = currentdate + monthDays[currentMonth - 1];
currentMonth --;
}
if (userMonth > currentMonth ) {
currentMonth += 12;
currentYear --;
}
const actualDate = currentdate - userDate;
const actualMonth = currentMonth - userMonth;
const actualYear = currentYear - userYear;
document.getElementById("age").innerHTML = 'Your Age is '+actualYear+' Years '+actualMonth+' Months '+actualDate+' Days';
console.log(userDate);
}
document.getElementById("submit-btn").addEventListener(
"click", () => {
document.querySelector("#age").className = "age";
}
)