London | 26-ITP-Sep | Bartosz Kawiak| Sprint 3 | Coursework-completed - #1582
bartoszkawiak wants to merge 14 commits into
Conversation
✅ Deploy Preview for cyf-onboarding-module ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| function capitalise(str) { | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } |
There was a problem hiding this comment.
This work.
The alternatives of reassigning the function parameters are:
- Use a separate
constvariable - Return the expression directly
Suggestion: Use AI to explore the trade-off of these approaches.
There was a problem hiding this comment.
Thank you CJ, 1st solution is commented out, more descriptive is displayed. I did explored the differences between them.
| function sum(a, b) { | ||
| return a + b | ||
| }; |
There was a problem hiding this comment.
Is the semicolon on line 18 necessary?
There was a problem hiding this comment.
Semicolon was deleted. I set up prettier to format text automatically.
| let bmiNum = weight / (height * height) | ||
| bmiNum=bmiNum.toFixed(1) | ||
| return bmiNum |
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.
I did expect it to return a string value, toFixed() method converts number to a string.
|
|
||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| const minutes = Number(time.slice(3, 5)); |
There was a problem hiding this comment.
Note: The .slice() method supports negative indices, which count positions from the end of the string.
For example, str.slice(-3) returns the substring containing last three characters from str.
There was a problem hiding this comment.
Thank you CJ, i changed value of the .slice()
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| return `${(hours - 12).toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")} pm`; | ||
| } else if (hours === 12) { | ||
| return `${hours}:${minutes.toString().padStart(2, "0")} pm`; | ||
| } else if (hours === 0) { | ||
| return `12:${minutes.toString().padStart(2, "0")} am`; | ||
| } | ||
| return `${time} am`; |
There was a problem hiding this comment.
This work.
Could also consider this approach:
- Convert
hours(hour in 24-hour clock) to equivalent hour in 12-hour clock and store the result inhour12. - Construct the 12 hour clock string from
hour12andminutesonce.
There was a problem hiding this comment.
Thanks for the suggestion. I can see how this approach would avoid repeating the same code and make the function cleaner.
cjyuan
left a comment
There was a problem hiding this comment.
Could you also respond to all my previous comments in addition to making change?
Suggestion: Use AI to explore "how to respond to comments in a PR".
| let bmiNum = weight / (height * height); | ||
| bmiNum = bmiNum.toFixed(1); | ||
| return typeof bmiNum; | ||
| } |
There was a problem hiding this comment.
Does this function return what you expect?
There was a problem hiding this comment.
Thank you, I forgot to edit the code after checking the typeof bmiNum. It should return a string.
|
Changes look good. Thanks for addressing all comments professionally. |

Learners, PR Template
Self checklist
Task code
CYF-1053
Changelist
Completed the Sprint 3 exercises, including working with functions, BMI calculations, time formatting, testing different inputs and fixing bugs found during testing.