Skip to content

Commit 8a3822b

Browse files
committed
Add format-time exercise
This follows on from the prep.
1 parent 8498a6f commit 8a3822b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Sprint-2/extend/format-time.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
);

Sprint-2/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ Here is a recommended order:
2323
In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar.
2424
You 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!
2525
You 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.

0 commit comments

Comments
 (0)