Skip to content

Commit 3acf90c

Browse files
authored
Merge pull request #12 from francescofranco/issue_11
Fixed #11 - Age calculations corrections
2 parents b7b408d + ea08b7b commit 3acf90c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h1>Age Calculator</h1>
2424
<h2>Age In</h2>
2525
<p>Milliseconds: <span id="milliseconds"></span></p>
2626
<p>Seconds: <span id="seconds"></span></p>
27-
<p>Minutes <span id="minutes"></span></p>
27+
<p>Minutes: <span id="minutes"></span></p>
2828
<p>Hours: <span id="hours"></span></p>
2929
</div>
3030
<div id="milestones">

main.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ function calculateAge() {
2323
const millisecondsInMonth = millisecondsInYear / 12
2424
const millisecondsInWeek = 7 * 24 * 60 * 60 * 1000
2525
const millisecondsInDay = 24 * 60 * 60 * 1000
26+
const millisecondsInHour = 60*60*1000;
27+
const millisecondsInMinute = 60*1000;
28+
const millisecondsInSecond = 1000;
2629

2730
const years = Math.floor(ageInMilliseconds / millisecondsInYear)
2831
const remainingMilliseconds = ageInMilliseconds % millisecondsInYear
@@ -32,18 +35,20 @@ function calculateAge() {
3235
const days = Math.floor(
3336
(remainingMilliseconds2 % millisecondsInWeek) / millisecondsInDay,
3437
)
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);
3641

3742
document.getElementById('years').textContent = years
3843
document.getElementById('months').textContent = months
3944
document.getElementById('weeks').textContent = weeks
4045
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;
4646

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;
4752

4853
// Calculate life milestones
4954
const retirementAge = 65; // Change to the desired retirement age
@@ -58,4 +63,6 @@ function calculateAge() {
5863
document.getElementById('age21').textContent = age21;
5964
document.getElementById('age30').textContent = age30;
6065
// Add more milestones as needed
61-
}
66+
};
67+
68+

0 commit comments

Comments
 (0)