Manchester | ITP-MAY-2026 | Yee Man Tsang | Sprint 2 | Coursework/Sprint-2#1416
Manchester | ITP-MAY-2026 | Yee Man Tsang | Sprint 2 | Coursework/Sprint-2#1416lintsang wants to merge 5 commits into
Conversation
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } No newline at end of file | ||
| return (weight / height**2).toFixed(1); |
There was a problem hiding this comment.
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?
Different types of values may appear identical in the console output, but they are represented and treated differently in the program. For example,
console.log(123); // Output 123
console.log("123"); // Output 123
// Treated differently in the program
let sum1 = 123 + 100; // Evaluate to 223 -- a number
let sum 2 = "123" + 100; // Evaluate to "123100" -- a string.There was a problem hiding this comment.
Thanks for reminder. I learnt that the types of value should be carefully considered when I am writing the code.
| // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase | ||
|
|
||
| function UPPER_SNAKE_CASE(string){ | ||
| upperString = string.toUpperCase(); |
There was a problem hiding this comment.
Should upperString be declared using const or let?
There was a problem hiding this comment.
I would use const here as I am not going to reassign the value in this case.
| // Use the MDN string documentation to help you find a solution | ||
| // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase | ||
|
|
||
| function UPPER_SNAKE_CASE(string){ |
There was a problem hiding this comment.
Could you look up the naming conventions in JavaScript? In particulars,
- Variable and function names
- Class and Types names
- Named constants
Then, update the function name according to those conventions.
There was a problem hiding this comment.
Many thanks. I clearly understand the naming conventions in Javascript now.
| while (numString.length < 2) { | ||
| numString = "0" + numString; | ||
| } |
There was a problem hiding this comment.
num is either a 1-digit or 2-digit number. A conditional statement is probably enough.
There was a problem hiding this comment.
Thanks for letting me know about this issue which I haven't noticed it before.
|
|
||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| const minute = pad(Number(time.slice(3,5))); |
There was a problem hiding this comment.
- What's the difference between
minuteandtime.slice(3, 5)?
There was a problem hiding this comment.
After reading the code again, I found the type of 'minute' is expected to be in string, while time.slice(3, 5) is already a string and I decided to assign to it directly. Thanks!
|
Have you made any change based on the comments? If so, you would need to push them to GitHub so that I can review them. |
|
Changes look good. I am not sure why GitHub shows me the older version of your files yesterday. |
Learners, PR Template
Self checklist
Changelist
Finished all exercises in all folders in sprint 2