(age)
| 22 | } |
| 23 | |
| 24 | function calcAge(age){ |
| 25 | let year = Math.floor(age); //21 |
| 26 | let remainingYear = age - year; //0.375 |
| 27 | |
| 28 | let monthDiff = remainingYear * 12; //4.5 |
| 29 | let month = Math.floor(monthDiff); //4 |
| 30 | |
| 31 | let remainingMonth = monthDiff - month; //0.5 |
| 32 | let day = Math.floor(remainingMonth * 30); //15 |
| 33 | |
| 34 | //display age to UI |
| 35 | displayAge(year, month, day); |
| 36 | } |
| 37 | |
| 38 | function displayAge(y,m,d){ |
| 39 |