Skip to content
Open
22 changes: 13 additions & 9 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
// Then when we call this function with the weight and height
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
// I have made a small change to the test cases to ensure they match the expected output to 1 decimal place
function calculateBMI(weight, height) {
// Calculate BMI using the formula: weight (kg) / (height (m) * height (m))
const bmi = weight / (height * height);

// Round to 1 decimal place and return
return bmi.toFixed(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these function calls output 123 in the console, but internally in the program,
the number 123 and the string "123" are stored and treated differently.

  console.log(123);
  console.log("123");

What type of value do you expect your function to return? A number or a string?
Does your function return the type of value you expect?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect the function to return a number, because a BMI is a numeric value. Yes, I tested the function, and it comes as a number.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you test if its return value is a number and not a string?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-10-26 185042

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a proper way to check the type of a value.

Can you ask AI (and then verify if needed) how to determine the type of a value in JS?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much, that was really helpful. I used (type of )and it showed me that my output was a string, and I changed it to a number

}
(calculateBMI(weight/hight*hight));
let bmi = 85 / (1.54 * 1.54);
console.log(bmi)
//here the result was 35.833307439446366 I need to round it to 1 decimal place
console.log(bmi.toFixed(1));
//now the output is 35.8


// Test cases
console.log(calculateBMI(85, 1.54)); // 35.8
console.log(calculateBMI(60, 1.65)); // 22.0
console.log(calculateBMI(72, 1.80)); // 22.2
// now the function is reusable and correct.
17 changes: 7 additions & 10 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
// You should call this function a number of times to check it works for different inputs

function toPounds(kg) {
const pounds = kg * 2.20462;

return pounds;
const pounds = kg * 2.20462;
return `${pounds.toFixed(2)} lbs`; // returns a string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not what is expected.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the code, and the output is a number, not a string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is supposed to convert pence to British pounds (similar to what you did in Sprint-1/3-mandatory-interpret/3-to-pounds.js

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this question is to convert the weight from kilograms to Pounds, not British pounds

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes you think that? What does the comments (lines 1-60 in the file say?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for all your help

}
console.log(toPounds(1));
console.log(toPounds(5));
console.log(toPounds(10));
// if I want to round the result to 2 decimal places I can use toFixed(2)
console.log(toPounds(1).toFixed(2));
console.log(toPounds(5).toFixed(2));
console.log(toPounds(10).toFixed(2));

// Test cases
console.log(toPounds(1)); //the output "2.20 lbs"
console.log(toPounds(5)); //the output is "11.02 lbs"
console.log(toPounds(10)); //the output is "22.05 lbs"