Skip to content

Commit dbb267b

Browse files
authored
Refactor calculateBMI to use toFixed for precision
Updated calculateBMI function to return a formatted string with one decimal place.
1 parent 15c4f3b commit dbb267b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
//}
2020

2121
function calculateBMI(weight, height) {
22-
//I had to search about how to include Math.floor and decimal digits to do line 30 correctly
23-
return Math.floor((weight / (height * height)) * 10) / 10;
22+
return (weight / (height * height)).toFixed(1);
2423
}
2524

2625
console.log(`Your Bmi is ${calculateBMI(70, 1.73)}`);
26+
27+
//why I used toFixed?
28+
//Its a javaScript method used to format a number's digit based on my request
29+
//it rounds the number and fill the digit with zeros if needed
30+
//also the parenthises mean, it will return the result as a text or string

0 commit comments

Comments
 (0)