-
Notifications
You must be signed in to change notification settings - Fork 0
/
date.js
34 lines (31 loc) · 1.05 KB
/
date.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
29
30
31
32
33
34
const ageYear = document.getElementById("ageYear");
const ageMonth = document.getElementById("ageMonth");
const ageDay = document.getElementById("ageDay");
function calculateAge() {
if (verifyInput() !== false) {
const birthDate = verifyInput();
const currentDate = new Date();
const ageInMilliseconds = currentDate - birthDate;
const ageDate = new Date(ageInMilliseconds);
const years = ageDate.getFullYear() - 1970;
const months = ageDate.getMonth();
const days = ageDate.getDate() - 1;
return { years: years, months: months, days: days };
}
return false;
}
function showBirthDate() {
if (calculateAge() !== false) {
const age = calculateAge();
const ageYear = new countUp.CountUp("ageYear", age.years, 3000);
const ageMonth = new countUp.CountUp("ageMonth", age.months, 3000);
const ageDay = new countUp.CountUp("ageDay", age.days, 3000);
ageDay.start();
ageMonth.start();
ageYear.start();
} else {
ageYear.textContent = "--";
ageMonth.textContent = "--";
ageDay.textContent = "--";
}
}