Manchester | 26-ITP-Sep | Precious Moses | Sprint 1 | FormatAs12HourClock - #1637
moses77-boop wants to merge 27 commits into
Conversation
… and period handling
…urate time formatting
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // function formatAs12HourClock(time) { | ||
|
|
||
| const hours = Number(time.slice(0, 2)); | ||
| // const hours = Number(time.slice(0, 2)); | ||
|
|
||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| // if (hours > 12) { | ||
| // return `${hours - 12}:00 pm`; | ||
| // } | ||
| // return `${time} am`; | ||
| // } | ||
|
|
||
| // export {formatAs12HourClock}; |
There was a problem hiding this comment.
Unused code should be removed to keep the codebase clean.
| return `${displayHour}:${minutePart}${period}`; | ||
| } | ||
| export {formatAs12HourClock}; | ||
| console.log(formatAs12HourClock("08:40")) |
There was a problem hiding this comment.
Code submitted in a PR should also be free of debugging code.
There was a problem hiding this comment.
Thanks for the feedback!
Fixed
| if(hours < 12){ | ||
| period = "am"; | ||
| } else { |
There was a problem hiding this comment.
The spacing before { is not fully consistent.
Suggestion:
- Look up the benefits of using a code formatter.
- Install the Prettier extension for VS Code, then:
- Use VS Code's Format Document feature to format your code.
- Optionally, enable Format On Save and Format On Paste to keep your code consistently formatted.
Resource: Visual Studio Code - Formatting
Note: The formatter may not work correctly if your code contains syntax errors.
There was a problem hiding this comment.
Thanks for your feedback.
I don't paste codes. I have Prettier extension installed already, not sure why it's not auto formatting, but I'll be happy to have a look and see how to configure it.
There was a problem hiding this comment.
This branch should only contain modified files in the format-clock-edge-cases folder.
Some of your recent commits have modified files in some other folders. Could you revert the changes made in those folders?
Note: Don't forget to add the "Needs review" label back to a PR whenever it is ready to be re-reviewed.
| let period; | ||
| if(hours < 12){ | ||
| period = "am"; | ||
| }else{ | ||
| period = "pm"; | ||
| } |
There was a problem hiding this comment.
Could practice using the ? : operator to simplify the code on line 5-10 into one line of code.
There was a problem hiding this comment.
Thanks for the feedback!
Code refactored.
| let displayHour = hours % 12; | ||
| if(displayHour === 0){ | ||
| displayHour = 12; | ||
| } |
There was a problem hiding this comment.
Code on lines 12-15 could also be simplified.
There was a problem hiding this comment.
Thanks for the feedback!
Code refactored.
| @@ -1,11 +1,18 @@ | |||
| function formatAs12HourClock(time) { | |||
| function formatAs12HourClock(time){ | |||
There was a problem hiding this comment.
Check out this coding style article about common format convention.
The current formatting is consistent but it doesn't look like the work of Prettier.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Changes are good. Well done! |
Self checklist
Task code
CYF-1197
Changelist
This PR contains fixes and tests with edge-cases.