-
-
Notifications
You must be signed in to change notification settings - Fork 389
London | 26-ITP-May | Bisrat Tesfay | Sprint 2 | Coursework/sprint 2 #1455
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?
Changes from all commits
70c3018
a86278a
ba5ec9e
5952762
550232a
4f46ec2
de9805d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,51 @@ console.assert( | |
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| ); | ||
|
|
||
| const currentOutput3 = formatAs12HourClock("00:00"); | ||
| const targetOutput3 = "12:00 am"; | ||
| console.assert( | ||
| currentOutput3 === targetOutput3, | ||
| `current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
| ); | ||
|
|
||
| const currentOutput4 = formatAs12HourClock("12:00"); | ||
| const targetOutput4 = "12:00 pm"; | ||
| console.assert( | ||
| currentOutput4 === targetOutput4, | ||
| `current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
| ); | ||
|
|
||
| const currentOutput5 = formatAs12HourClock("14:30"); | ||
| const targetOutput5 = "2:30 pm"; | ||
| console.assert( | ||
| currentOutput5 === targetOutput5, | ||
| `current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
| ); | ||
|
|
||
| console.log(formatAs12HourClock("08:00")); | ||
| console.log(formatAs12HourClock("23:00")); | ||
| console.log(formatAs12HourClock("00:00")); | ||
| console.log(formatAs12HourClock("12:00")); | ||
| console.log(formatAs12HourClock("14:30")); | ||
|
|
||
| //The function did not handle the edge cases 00:00 and 12:00. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are absolutely correct that it didn't handle those two edge cases! Please update the function accordingly to ensure it does handle them (and also handles slightly different inputs as well, please refer to the prep steps for a reminder of the kinds of inputs you need to handle).
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback! I've updated the function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice one! |
||
| // The correct function should be like this | ||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| const minutes = time.slice(2); | ||
|
|
||
| if (hours === 0) { | ||
| return `12${minutes} am`; | ||
| } | ||
|
|
||
| if (hours === 12) { | ||
| return `12${minutes} pm`; | ||
| } | ||
|
|
||
| if (hours > 12) { | ||
| return `${hours - 12}${minutes} pm`; | ||
| } | ||
|
|
||
| return `${time} am`; | ||
| } | ||
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.
This is true, but I'm looking for a little more specifics. When the line
is run, what do you see and why? Your comment should provide a thorough explanation of this.
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.
The function
multiply(a, b)prints the result usingconsole.log(a * b), but it does not return a value. Whenmultiply(10, 32)is called inside the template literal, it first prints320to the console. Then, because the function has noreturnstatement, it returnsundefined. As a result, the secondconsole.logprints:The result of multiplying 10 and 32 is undefinedThis happens because
console.log()only displays a value on the screen, whilereturnsends a value back to where the function was called.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.
Yep, spot on - could you please update your answer in the file to use this level of detail? Then I'm happy to mark as complete 🙂