Skip to content

Commit e39749f

Browse files
committed
fix: improve BMI calculation precision and return type
1 parent 23a25ca commit e39749f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Sprint-2/3-mandatory-implement/1-bmi.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// It should return their Body Mass Index to 1 decimal place
1616

1717
function calculateBMI(weight, height) {
18-
return (weight / height ** 2).toFixed(1);
18+
const bmi = weight / height ** 2;
19+
return Number(bmi.toFixed(1));
1920
}
2021

2122
console.log(calculateBMI(70, 1.73));

Sprint-2/5-stretch-extend/format-time.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
77
const minutes = time.slice(3, 5);
8-
if (hours >= 12) {
8+
9+
if (hours === 0) {
10+
return `12:${minutes} am`;
11+
}
12+
13+
if (hours === 12) {
14+
return `${hours}:${minutes} pm`;
15+
}
16+
17+
if (hours > 12) {
918
return `${hours !== 12 ? hours - 12 : hours}:${minutes} pm`;
1019
}
1120
return `${time} am`;
@@ -27,7 +36,7 @@ console.assert(
2736

2837
// Midnight
2938
const outMidnight = formatAs12HourClock("00:00");
30-
const targetMidnight = "00:00 am";
39+
const targetMidnight = "12:00 am";
3140
console.assert(
3241
outMidnight === targetMidnight,
3342
`current output: ${outMidnight}, target output: ${targetMidnight}`

0 commit comments

Comments
 (0)