-
-
Couldn't load subscription status.
- Fork 239
Sheffield | 25-ITP-Sep | Xiayidan Abuxuukuer | Sprint 2 | Coursework #781
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 5 commits
237a6b1
e72c25e
d904467
e897f8b
8fb5a39
029c9bc
658658e
d077e75
b08b31e
b0c66f4
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 |
|---|---|---|
|
|
@@ -3,22 +3,36 @@ | |
| // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. | ||
|
|
||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| // Expect time in "HH:MM" format | ||
| let hours = Number(time.slice(0, 2)); | ||
| let mins = time.slice(3); | ||
|
||
|
|
||
| if (hours === 0) { | ||
| return `12:${mins} am`; | ||
| } | ||
|
|
||
| if (hours === 12) { | ||
| return `12:${mins} pm`; | ||
| } | ||
|
|
||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| let newHr = hours - 12; | ||
| // pad single digits like 1:00 -> 01:00 | ||
| return `${String(newHr).padStart(2, "0")}:${mins} pm`; | ||
| } | ||
|
|
||
| return `${time} am`; | ||
| } | ||
|
|
||
| const currentOutput = formatAs12HourClock("08:00"); | ||
| const targetOutput = "08:00 am"; | ||
| let currentOutput = formatAs12HourClock("08:00"); | ||
| let targetOutput = "08:00 am"; | ||
| console.assert( | ||
| currentOutput === targetOutput, | ||
| `current output: ${currentOutput}, target output: ${targetOutput}` | ||
| ); | ||
|
|
||
| const currentOutput2 = formatAs12HourClock("23:00"); | ||
| const targetOutput2 = "11:00 pm"; | ||
| let currentOutput2 = formatAs12HourClock("23:00"); | ||
| let targetOutput2 = "11:00 pm"; | ||
| console.assert( | ||
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
|
|
||
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 the function to return? A number or a string?
Does your function return the type of value you expect?