File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ // This is the latest solution to the problem from the prep.
2+ // 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.
3+
4+ function formatAs12HourClock ( time ) {
5+ const hours = Number ( time . slice ( 0 , 2 ) ) ;
6+ if ( hours > 12 ) {
7+ return `${ hours - 12 } :00 pm` ;
8+ }
9+ return `${ time } am` ;
10+ }
11+
12+ const currentOutput = formatAs12HourClock ( "08:00" ) ;
13+ const targetOutput = "08:00 am" ;
14+ console . assert (
15+ currentOutput === targetOutput ,
16+ `current output: ${ currentOutput } , target output: ${ targetOutput } `
17+ ) ;
18+
19+ const currentOutput2 = formatAs12HourClock ( "23:00" ) ;
20+ const targetOutput2 = "11:00 pm" ;
21+ console . assert (
22+ currentOutput2 === targetOutput2 ,
23+ `current output: ${ currentOutput2 } , target output: ${ targetOutput2 } `
24+ ) ;
Original file line number Diff line number Diff line change @@ -23,3 +23,8 @@ Here is a recommended order:
2323In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar.
2424You must use documentation to make sense of anything unfamiliar - learning how to look things up this way is a fundamental part of being a developer!
2525You can also use ` console.log ` to check the value of different variables in the code.
26+
27+ ## Extend
28+
29+ In the prep for this sprint, we developed a function to convert 24 hour clock times to 12 hour clock times.
30+ 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.
You can’t perform that action at this time.
0 commit comments