()
| 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() |
| 11 | } |
| 12 | let currentYear=today.getFullYear(); |
| 13 | let currentMonth=today.getMonth()+1; |
| 14 | let currentDay=today.getDate(); |
| 15 | |
| 16 | |
| 17 | leapChecker(currentYear); |
| 18 | |
| 19 | |
| 20 | if(birthDetails.year>currentYear || (birthDetails.month > currentMonth && birthDetails.year == currentYear) || |
| 21 | (birthDetails.date > currentDay && birthDetails.month == currentMonth && birthDetails.year == currentYear)){ |
| 22 | alert("Enter Valid Date"); |
| 23 | |
| 24 | } |
| 25 | birthYear=currentYear-birthDetails.year; |
| 26 | if(currentMonth>=birthDetails.month){ |
| 27 | birthMonth=currentMonth-birthDetails.month; |
| 28 | } |
| 29 | else{ |
| 30 | birthYear--; |
| 31 | birthMonth=12+currentMonth-birthDetails.month; |
| 32 | } |
| 33 | if(currentDay>=birthDetails.date){ |
| 34 | birthDate=currentDay-birthDetails.date; |
| 35 | |
| 36 | } |
| 37 | else{ |
| 38 | birthMonth--; |
| 39 | let days=months[currentMonth-2]; |
| 40 | birthDate=days+currentDay- birthDetails.date; |
| 41 | if(birthMonth<0){ |
| 42 | birthMonth=11; |
| 43 | birthYear--; |
| 44 | } |
| 45 | |
| 46 | } |
| 47 | |
| 48 | display(birthDate,birthMonth,birthYear); |
| 49 | checkBirthday(birthDetails.date,birthDetails.month,birthDetails.year,currentDay,currentMonth,currentYear); |
| 50 | |
| 51 | } |
| 52 | function display(bdate,bmonth,byear){ |
| 53 | document.getElementById("years").textContent=byear; |
| 54 | document.getElementById("months").textContent=bmonth; |
nothing calls this directly
no test coverage detected