33// Your task is to write tests for as many different groups of input data or edge cases as you can,
44// and fix any bugs you find.
55
6- function formatAs12HourClock ( time ) {
7- const hours = Number ( time . slice ( 0 , 2 ) ) ;
8- if ( hours > 12 ) {
9- return `${ hours - 12 } :00 pm` ;
10- }
11- return `${ time } am` ;
12- }
13-
14- const currentOutput = formatAs12HourClock ( "08:00" ) ;
15- const targetOutput = "08:00 am" ;
16- console . assert (
17- currentOutput === targetOutput ,
18- `current output: ${ currentOutput } , target output: ${ targetOutput } `
19- ) ;
20-
21- const currentOutput2 = formatAs12HourClock ( "23:00" ) ;
22- const targetOutput2 = "11:00 pm" ;
23- console . assert (
24- currentOutput2 === targetOutput2 ,
25- `current output: ${ currentOutput2 } , target output: ${ targetOutput2 } `
26- ) ;
27-
28- const currentOutput3 = formatAs12HourClock ( "00:00" ) ;
29- const targetOutput3 = "12:00 am" ;
30- console . assert (
31- currentOutput3 === targetOutput3 ,
32- `current output: ${ currentOutput3 } , target output: ${ targetOutput3 } `
33- ) ;
34- const currentOutput4 = formatAs12HourClock ( "12:00" ) ;
35- const targetOutput4 = "12:00 pm" ;
36- console . assert (
37- currentOutput4 === targetOutput4 ,
38- `current output: ${ currentOutput4 } , target output: ${ targetOutput4 } `
39- ) ;
40-
41- const currentOutput5 = formatAs12HourClock ( "13:00" ) ;
42- const targetOutput5 = "01:00 pm" ;
43- console . assert (
44- currentOutput5 === targetOutput5 ,
45- `current output: ${ currentOutput5 } , target output: ${ targetOutput5 } `
46-
47- ) ;
48-
49- const currentOutput7 = formatAs12HourClock ( "25:00" ) ;
50- const targetOutput7 = "01:00 am" ;
51- console . assert (
52- currentOutput7 === targetOutput7 ,
53- `current output: ${ currentOutput7 } , target output: ${ targetOutput7 } `
6+ // function formatAs12HourClock(time) {
7+ // const hours = Number(time.slice(0, 2));
8+ // if (hours > 12) {
9+ // return `${hours - 12}:00 pm`;
10+ // }
11+ // return `${time} am`;
12+ // }
13+
14+ // const currentOutput = formatAs12HourClock("08:00");
15+ // const targetOutput = "08:00 am";
16+ // console.assert(
17+ // currentOutput === targetOutput,
18+ // `current output: ${currentOutput}, target output: ${targetOutput}`
19+ // );
20+
21+ // const currentOutput2 = formatAs12HourClock("23:00");
22+ // const targetOutput2 = "11:00 pm";
23+ // console.assert(
24+ // currentOutput2 === targetOutput2,
25+ // `current output: ${currentOutput2}, target output: ${targetOutput2}`
26+ // );
27+
28+ // const currentOutput3 = formatAs12HourClock("00:00");
29+ // const targetOutput3 = "12:00 am";
30+ // console.assert(
31+ // currentOutput3 === targetOutput3,
32+ // `current output: ${currentOutput3}, target output: ${targetOutput3}`
33+ // );
34+ // const currentOutput4 = formatAs12HourClock("12:00");
35+ // const targetOutput4 = "12:00 pm";
36+ // console.assert(
37+ // currentOutput4 === targetOutput4,
38+ // `current output: ${currentOutput4}, target output: ${targetOutput4}`
39+ // );
40+
41+ // const currentOutput5 = formatAs12HourClock("13:00");
42+ // const targetOutput5 = "01:00 pm";
43+ // console.assert(
44+ // currentOutput5 === targetOutput5,
45+ // `current output: ${currentOutput5}, target output: ${targetOutput5}`
46+
47+ // );
48+
49+ // const currentOutput7 = formatAs12HourClock("25:00");
50+ // const targetOutput7 = "01:00 am";
51+ // console.assert(
52+ // currentOutput7 === targetOutput7,
53+ // `current output: ${currentOutput7}, target output: ${targetOutput7}`
5454
55- )
55+ // )
5656
5757// console.assert(formatAs12HourClock("08:00") === "08:00 am");
5858// console.assert(formatAs12HourClock("23:00") === "11:00 pm");
@@ -87,7 +87,10 @@ const targetOutput6 = "11:00 pm";
8787console . assert (
8888 currentOutput6 === targetOutput6 ,
8989 `current output: ${ currentOutput6 } , target output: ${ targetOutput6 } `
90+
9091)
92+ console . log ( currentOutput6 )
93+
9194
9295
9396// Updated const minutes = time.slice(3) --- to const minutes = time.slice(-2)
0 commit comments