Skip to content

Commit 301c8f1

Browse files
committed
write tests, fix bugs
1 parent c81c5df commit 301c8f1

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// This is the latest solution to the problem from the prep.
22
// Make sure to do the prep before you do the coursework
3-
// 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+
// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any
4+
// bugs you find.
45

56
function formatAs12HourClock(time) {
6-
const hours = Number(time.slice(0, 2));
7-
if (hours > 12) {
8-
return `${hours - 12}:00 pm`;
9-
}
7+
if (Number(time.slice(0, 2)) === 12) {
8+
return `${time} pm` // if time is "12:00" it will show
9+
//12:00 pm
10+
} else if (Number(time.slice(0, 2))=== 24) {
11+
return `00:00 am`;
12+
} else if (Number(time.slice(0, 2)) > 12) {
13+
return `${Number(time.slice(0, 2)) - 12}:00 pm`;
14+
}
1015
return `${time} am`;
1116
}
12-
1317
const currentOutput = formatAs12HourClock("08:00");
1418
const targetOutput = "08:00 am";
1519
console.assert(
@@ -23,3 +27,24 @@ console.assert(
2327
currentOutput2 === targetOutput2,
2428
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2529
);
30+
const currentOutput3 = formatAs12HourClock("00:00");//
31+
const targetOutput3 = "00:00 am";// expecting new test to return "00:00 am"
32+
console.assert(
33+
currentOutput3 === targetOutput3,
34+
`current output: ${currentOutput3}, target output: ${targetOutput3}`
35+
); // if currentOutput3 and targetOutput3 do not match, the assertion message will be given.
36+
37+
const currentOutput4 = formatAs12HourClock("12:00");//
38+
const targetOutput4 = "12:00 pm"; // expected output for "12:00" is "12:00 pm"
39+
console.assert(
40+
currentOutput4 === targetOutput4,
41+
`current output: ${currentOutput4}, target output: ${targetOutput4}`
42+
);// if currentOutput and targetOutput do not match, the assertion message will be given.
43+
const currentOutput5 = formatAs12HourClock("24:00");
44+
const targetOutput5 = "00:00 am";
45+
console.assert(
46+
currentOutput5 === targetOutput5,
47+
`current output5: ${currentOutput5}, target output5: ${targetOutput5}`
48+
); // if 24:00 is entered and the output is not "00:00 am" the assertion message will be given
49+
50+

0 commit comments

Comments
 (0)