| 2 | const error = document.querySelector('.error'); |
| 3 | |
| 4 | function getAge(){ |
| 5 | |
| 6 | const dobValue = document.getElementById('dob').value; |
| 7 | |
| 8 | //if the dob value is falsy, then simply return |
| 9 | if(!dobValue) return; |
| 10 | |
| 11 | //stores dob ----- Date Wed Sep 01 1999 05:30:00 GMT+0530 (India Standard Time) |
| 12 | let dob = new Date(dobValue); |
| 13 | |
| 14 | //current date |
| 15 | const today = new Date(); |
| 16 | |
| 17 | |
| 18 | let diff = today - dob; |
| 19 | let age = diff / (1000 * 60 * 60 * 24 * 365); //21.375 |
| 20 | |
| 21 | calcAge(age); |
| 22 | } |
| 23 | |
| 24 | function calcAge(age){ |
| 25 | let year = Math.floor(age); //21 |