@@ -23,6 +23,9 @@ function calculateAge() {
23
23
const millisecondsInMonth = millisecondsInYear / 12
24
24
const millisecondsInWeek = 7 * 24 * 60 * 60 * 1000
25
25
const millisecondsInDay = 24 * 60 * 60 * 1000
26
+ const millisecondsInHour = 60 * 60 * 1000 ;
27
+ const millisecondsInMinute = 60 * 1000 ;
28
+ const millisecondsInSecond = 1000 ;
26
29
27
30
const years = Math . floor ( ageInMilliseconds / millisecondsInYear )
28
31
const remainingMilliseconds = ageInMilliseconds % millisecondsInYear
@@ -32,18 +35,20 @@ function calculateAge() {
32
35
const days = Math . floor (
33
36
( remainingMilliseconds2 % millisecondsInWeek ) / millisecondsInDay ,
34
37
)
35
- // append the result to the result element
38
+ const ageInHours = Math . floor ( ageInMilliseconds / millisecondsInHour ) ;
39
+ const ageInMinutes = Math . floor ( ageInMilliseconds / millisecondsInMinute ) ;
40
+ const ageInSeconds = Math . floor ( ageInMilliseconds / millisecondsInSecond ) ;
36
41
37
42
document . getElementById ( 'years' ) . textContent = years
38
43
document . getElementById ( 'months' ) . textContent = months
39
44
document . getElementById ( 'weeks' ) . textContent = weeks
40
45
document . getElementById ( 'days' ) . textContent = days
41
- document . getElementById ( 'hours' ) . textContent = days * 24
42
- document . getElementById ( 'minutes' ) . textContent = days * 24 * 60
43
- document . getElementById ( 'seconds' ) . textContent = days * 24 * 60 * 60
44
- document . getElementById ( 'milliseconds' ) . textContent =
45
- ( millisecondsInYear * ageInMilliseconds ) / millisecondsInYear ;
46
46
47
+ //Section Age in
48
+ document . getElementById ( 'hours' ) . textContent = ageInHours ;
49
+ document . getElementById ( 'minutes' ) . textContent = ageInMinutes ;
50
+ document . getElementById ( 'seconds' ) . textContent = ageInSeconds ;
51
+ document . getElementById ( 'milliseconds' ) . textContent = ageInMilliseconds ;
47
52
48
53
// Calculate life milestones
49
54
const retirementAge = 65 ; // Change to the desired retirement age
@@ -58,4 +63,6 @@ function calculateAge() {
58
63
document . getElementById ( 'age21' ) . textContent = age21 ;
59
64
document . getElementById ( 'age30' ) . textContent = age30 ;
60
65
// Add more milestones as needed
61
- }
66
+ } ;
67
+
68
+
0 commit comments