Skip to content

Commit 3de19b0

Browse files
authored
Merge pull request #41 from CodeYourFuture/format-time
Add format-time exercise
2 parents 87cc8f7 + 79f8828 commit 3de19b0

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,10 @@ Here is a recommended order:
2121
## Interpret
2222

2323
In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar.
24-
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!
24+
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)