File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 1414// Then when we call this function with the weight and height
1515// It should return their Body Mass Index to 1 decimal place
1616
17+ /**
1718function calculateBMI(weight, height) {
1819 // return the BMI of someone based off their weight and height
19- }
20+ }
21+ */
22+
23+ /**
24+ This function works by:
25+
26+ Squaring the height.
27+
28+ Dividing the weight by the squared height.
29+
30+ Using toFixed(1) to round the BMI to 1 decimal place and converting it back to a number.
31+ */
32+
33+ // Function to calculate BMI
34+ function calculateBMI ( weight , height ) {
35+ // Calculate BMI: weight divided by height squared
36+ const bmi = weight / ( height * height ) ;
37+
38+ // Round the result to 1 decimal place and return
39+ return Number ( bmi . toFixed ( 1 ) ) ;
40+ }
41+
42+ // Example usage:
43+ console . log ( calculateBMI ( 70 , 1.73 ) ) ; // Output: 23.4
44+ console . log ( calculateBMI ( 60 , 1.6 ) ) ; // Output: 23.4
45+ console . log ( calculateBMI ( 90 , 1.8 ) ) ; // Output: 27.8
46+
47+
You can’t perform that action at this time.
0 commit comments