File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Sprint-2/5-stretch-extend Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,48 @@ console.assert(
2323 currentOutput2 === targetOutput2 ,
2424 `current output: ${ currentOutput2 } , target output: ${ targetOutput2 } `
2525) ;
26+
27+ //Test cases
28+ console . assert (
29+ formatAs12HourClock ( "08:00" ) === "08:00 am" ,
30+ "Test 1 failed"
31+ ) ;
32+
33+ console . assert (
34+ formatAs12HourClock ( "23:15" ) === "11:15 pm" ,
35+ "Test 2 failed"
36+ ) ;
37+
38+ console . assert (
39+ formatAs12HourClock ( "00:05" ) === "12:05 am" ,
40+ "Test 3 failed"
41+ ) ;
42+
43+ console . assert (
44+ formatAs12HourClock ( "12:30" ) === "12:30 pm" ,
45+ "Test 4 failed"
46+ ) ;
47+
48+ console . assert (
49+ formatAs12HourClock ( "13:45" ) === "01:45 pm" ,
50+ "Test 5 failed"
51+ ) ;
52+
53+ //fixed version
54+ /*function formatAs12HourClock(time) {
55+ let hours = Number(time.slice(0, 2));
56+ const minutes = time.slice(3); // keep the minutes as they are
57+ let period = "am";
58+
59+ if (hours === 0) {
60+ hours = 12; // midnight
61+ } else if (hours === 12) {
62+ period = "pm"; // noon
63+ } else if (hours > 12) {
64+ hours -= 12;
65+ period = "pm";
66+ }
67+
68+ return `${hours.toString().padStart(2, "0")}:${minutes} ${period}`;
69+ }
70+ */
You can’t perform that action at this time.
0 commit comments