MCPcopy Create free account
hub / github.com/AyushSaini00/60minuteJavaScript / getAge

Function getAge

Age-Calculator/app.js:4–22  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2const error = document.querySelector('.error');
3
4function 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
24function calcAge(age){
25 let year = Math.floor(age); //21

Callers

nothing calls this directly

Calls 1

calcAgeFunction · 0.85

Tested by

no test coverage detected