-
-
Notifications
You must be signed in to change notification settings - Fork 299
London | 26-ITP-Jan | Abdul Moiz | Sprint 2 | Sprint 2 #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is generally good.
|
|
||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| let newStr = `${str[0].toUpperCase()}${str.slice(1)}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a variable not needed to be reassigned a value, a better practice is to use const instead of let.
| } No newline at end of file | ||
| let heightSquared = height * height; | ||
| let bmi = weight / heightSquared; | ||
| return bmi.toFixed(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.| console.assert(formatAs12HourClock("01:00") === "01:00 am"); | ||
| console.assert(formatAs12HourClock("11:59") === "11:59 am"); | ||
|
|
||
| // Noon | ||
| console.assert(formatAs12HourClock("12:00") === "12:00 pm"); | ||
| console.assert(formatAs12HourClock("12:30") === "12:30 pm"); | ||
|
|
||
| // Afternoon / evening | ||
| console.assert(formatAs12HourClock("13:00") === "1:00 pm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output on lines 56 and 48 have slightly different format.
Can you modify the function to return a string in a consistent format?
| // Updated function: | ||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| const minutes = time.slice(3, 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can also consider time.slice(-2) (a bit more expressive).
Learners, PR Template
Self checklist
Changelist
Completed all the exercises in Sprint 2 directory
Questions
N/A