Cape Town | 26-ITP-Sept | Leigh Ross | Sprint 3 | Coursework: Sprint 3 - #1580
leigh-ross wants to merge 42 commits into
Conversation
…odule-JavaScript-Fundamentals into coursework/sprint-2 "Trying to fix my commits"
✅ Deploy Preview for cyf-onboarding-module ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| function capitalise(str) { | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } |
There was a problem hiding this comment.
This works.
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.
|
|
||
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| return (weight / (height * height)).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.| function UPPER_SNAKE_CASE(str) { | ||
| let snake_case = str.replaceAll(" ", "_"); | ||
| return snake_case.toUpperCase() | ||
| } |
There was a problem hiding this comment.
Could you look up the naming conventions in JavaScript? In particular,
- Variable and function names
- Class and Types names
- Named constants
Then, update the variable names according to those conventions.
|
|
||
| console.log(`£${pounds}.${pence}`); | ||
| } |
There was a problem hiding this comment.
Outputting a value via console.log is not the same as returning that value. Could you update the code to return the pound string?
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| if (hours >= 12) { | ||
| return `${hours - 12}:${time.slice(3)} pm`; |
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.
| { input: "00:00", expected: "12:00 am" }, // midnight | ||
| { input: "01:00", expected: "01:00 am" }, | ||
| { input: "02:00", expected: "02:00 am" }, // your failing test | ||
| { input: "09:00", expected: "09:00 am" }, | ||
| { input: "11:59", expected: "11:59 am" }, | ||
| { input: "12:00", expected: "12:00 pm" }, // noon | ||
| { input: "12:30", expected: "12:30 pm" }, | ||
| { input: "13:00", expected: "01:00 pm" }, | ||
| { input: "23:00", expected: "11:00 pm" }, // your other test | ||
| { input: "23:59", expected: "11:59 pm" }, |
There was a problem hiding this comment.
These are good test data. However, your function could not yet pass all these tests. Can you update your code accordingly?

Learners, PR Template
Self checklist
Task code
CYF-1053
Changelist