We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 26dd684 commit bfe65daCopy full SHA for bfe65da
1 file changed
Sprint-2/5-stretch-extend/format-time.js
@@ -3,9 +3,8 @@
3
// 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.
4
;
5
function formatAs12HourClock(time) {
6
- const hours = Number(time.slice(0, 2));
7
- const minutes = time.slice(3, 5);
8
- if (h)
+ const [hourString, minutes] = time.split(":");
+const hours = Number(hourString);
9
10
if (hours === 0) {
11
return `12:${minutes} am`;
@@ -15,11 +14,11 @@ function formatAs12HourClock(time) {
15
14
return `12:${minutes} pm`;
16
}
17
18
- if (hours > 12) {
19
- return `${hours - 12}:${minutes} pm`;
+ if (hours < 12) {
+ return `${hours}:${minutes} am`;
20
21
22
- return `${time} am`;
+ return `${hours - 12}:${minutes} pm`;
23
24
25
// Existing tests
0 commit comments