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 4 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.| // 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?
| // 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.
| 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.
|
|
||
| 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)?
| const currentOutput5 = formatAs12HourClock("00:00"); | ||
| const targetOutput5 = "00:00 am"; |
There was a problem hiding this comment.
Shouldn't "00:00" be converted to "12:00 am"?
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| const minute = pad(Number(time.slice(3,5))); | ||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| return `${hours - 12}:${minute} pm`; | ||
| } else if (hours == 12 & minute == '00'){ | ||
| return `${time} pm`; | ||
| } | ||
| return `${time} am`; | ||
| } |
There was a problem hiding this comment.
What do you expect from the following function calls?
formatAs12HourClock("08:35");
formatAs12HourClock("20:35");
formatAs12HourClock("12:34");
formatAs12HourClock("00:34");
Do they return the values you expected? Are the returned values consistently formatted?
Learners, PR Template
Self checklist
Changelist
Finished all exercises in all folders in sprint 2