Skip to content

Commit 7ae1a0c

Browse files
authored
Update script.js
1 parent 2af7df5 commit 7ae1a0c

File tree

1 file changed

+42
-44
lines changed

1 file changed

+42
-44
lines changed

age-calculator/script.js

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,70 @@
1-
const months=[31,28,31,30,31,30,31,31,30,31,30,31];
2-
3-
function ageCalc(){
4-
let today=new Date();
5-
let inputDate= new Date(document.getElementById("date").value);
6-
let birthMonth,birthDate,birthYear;
7-
let birthDetails={
8-
date:inputDate.getDate(),
9-
month:inputDate.getMonth()+1,
10-
year:inputDate.getFullYear()
1+
@ @ - 0, 0 + 1, 72 @ @
2+
const months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
3+
4+
function ageCalc() {
5+
let today = new Date();
6+
let inputDate = new Date(document.getElementById("date").value);
7+
let birthMonth, birthDate, birthYear;
8+
let birthDetails = {
9+
date: inputDate.getDate(),
10+
month: inputDate.getMonth() + 1,
11+
year: inputDate.getFullYear()
1112
}
12-
let currentYear=today.getFullYear();
13-
let currentMonth=today.getMonth()+1;
14-
let currentDay=today.getDate();
13+
let currentYear = today.getFullYear();
14+
let currentMonth = today.getMonth() + 1;
15+
let currentDay = today.getDate();
1516

1617

1718
leapChecker(currentYear);
1819

1920

20-
if(birthDetails.year>currentYear || (birthDetails.month > currentMonth && birthDetails.year == currentYear) ||
21-
(birthDetails.date > currentDay && birthDetails.month == currentMonth && birthDetails.year == currentYear)){
21+
if (birthDetails.year > currentYear || (birthDetails.month > currentMonth && birthDetails.year == currentYear) ||
22+
(birthDetails.date > currentDay && birthDetails.month == currentMonth && birthDetails.year == currentYear)) {
2223
alert("Enter Valid Date");
23-
24-
}
25-
birthYear=currentYear-birthDetails.year;
26-
if(currentMonth>=birthDetails.month){
27-
birthMonth=currentMonth-birthDetails.month;
24+
2825
}
29-
else{
26+
birthYear = currentYear - birthDetails.year;
27+
if (currentMonth >= birthDetails.month) {
28+
birthMonth = currentMonth - birthDetails.month;
29+
} else {
3030
birthYear--;
31-
birthMonth=12+currentMonth-birthDetails.month;
31+
birthMonth = 12 + currentMonth - birthDetails.month;
3232
}
33-
if(currentDay>=birthDetails.date){
34-
birthDate=currentDay-birthDetails.date;
33+
if (currentDay >= birthDetails.date) {
34+
birthDate = currentDay - birthDetails.date;
3535

36-
}
37-
else{
36+
} else {
3837
birthMonth--;
39-
let days=months[currentMonth-2];
40-
birthDate=days+currentDay- birthDetails.date;
41-
if(birthMonth<0){
42-
birthMonth=11;
38+
let days = months[currentMonth - 2];
39+
birthDate = days + currentDay - birthDetails.date;
40+
if (birthMonth < 0) {
41+
birthMonth = 11;
4342
birthYear--;
4443
}
4544

4645
}
4746

48-
display(birthDate,birthMonth,birthYear);
49-
47+
display(birthDate, birthMonth, birthYear);
48+
5049
}
51-
function display(bdate,bmonth,byear){
52-
document.getElementById("years").textContent=byear;
53-
document.getElementById("months").textContent=bmonth;
54-
document.getElementById("days").textContent=bdate;
50+
51+
function display(bdate, bmonth, byear) {
52+
document.getElementById("years").textContent = byear;
53+
document.getElementById("months").textContent = bmonth;
54+
document.getElementById("days").textContent = bdate;
5555

5656

5757
}
5858

59-
function leapChecker(year){
60-
if(year%4==0 || (year%100==0 && year%400==0)){
61-
months[1]=29;
62-
}
63-
else{
64-
months[1]=28;
59+
function leapChecker(year) {
60+
if (year % 4 == 0 || (year % 100 == 0 && year % 400 == 0)) {
61+
months[1] = 29;
62+
} else {
63+
months[1] = 28;
6564
}
6665

6766

6867

69-
7068

71-
}
7269

70+
}

0 commit comments

Comments
 (0)