West Midlands | May 2026 | Muhammad-Burhan Mustafa | Sprint 2 | Module-Structuring-and-Testing-Data#1443
Conversation
| let numWeight = Number(weight.slice(0, -2)); | ||
| let numHeight = Number(height.slice(0, -1)); | ||
| let BMI = numWeight / (numHeight * numHeight); | ||
| return Math.round(BMI * 10) / 10; |
There was a problem hiding this comment.
Generally if we are designing a function to perform a calculation, it's reasonable to expect the inputs to be numerical. When the function description says "weight in kg", it isn't asking explicitly to accept the input of "70kg" but rather to accept the input of 70 and write a function that interprets that as a kg value of weight.
| return string.toUpperCase().replaceAll(" ", "_"); | ||
| } | ||
|
|
||
| console.log(upperSnakeCase("i love cyf you guys are awesome!")); |
| // You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
|
||
| // You should call this function a number of times to check it works for different inputs | ||
| function ToPounds(penceString) { |
There was a problem hiding this comment.
In JavaScript, standard variables and functions should be named with lowerCamelCase style, not UpperCamelCase. When we declare something with UpperCamelCase, as you have done here, we're actually suggesting it is something called a constructor or class (which you don't need to learn about right now, just know that that's not what we're doing here!)
|
|
||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| // // Line 7 uses the const variable num which has been assigned the value 103 and the last digit of that number is 3. When the function getLastDigit is called it |
There was a problem hiding this comment.
Would the behaviour be different if it were a let variable?
|
|
||
| // =============> write your explanation here | ||
| // Since the parameter and variable have the same name, decimalNumber, we will get an error as we can not declare a | ||
| // variable of the same name with in the functions local scope |
There was a problem hiding this comment.
What's another problem with the original code?
Self checklist
Changelist
All tasks in sprint 2 completed.