Skip to content

Commit 004cb3b

Browse files
committed
Minutes solved
1 parent e09db2b commit 004cb3b

1 file changed

Lines changed: 89 additions & 1 deletion

File tree

‎Sprint-3/5-stretch-extend/format-time.js‎

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,94 @@
22
// Make sure to do the prep before you do the coursework
33
// 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.
44

5+
// function formatAs12HourClock(time) {
6+
// const hours = Number(time.slice(0, 2));
7+
// if (hours > 12) {
8+
// return `${hours - 12}:00 pm`;
9+
// }
10+
// return `${time} am`;
11+
// }
12+
// // console.log(formatAs12HourClock("10:15"));
13+
14+
// // Early Morning: ================> assertion passed
15+
// let currentOutput = formatAs12HourClock("08:30");
16+
// let targetOutput = "08:30 am";
17+
// console.assert(
18+
// currentOutput === targetOutput,
19+
// `current output: ${currentOutput}, target output: ${targetOutput}`
20+
// );
21+
// console.log(formatAs12HourClock("08:30"))
22+
23+
// // Mid-morning ==============> assertion passed
24+
// currentOutput = formatAs12HourClock("10:00");
25+
// targetOutput = "10:00 am";
26+
// console.assert(
27+
// currentOutput === targetOutput,
28+
// `current output: ${currentOutput}, target output: ${targetOutput}`
29+
// );
30+
// console.log(formatAs12HourClock("10.00"))
31+
32+
// // Late morning ============> assertion passed
33+
// currentOutput = formatAs12HourClock("11:45");
34+
// targetOutput = "11:45 am";
35+
// console.assert(
36+
// currentOutput === targetOutput,
37+
// `current output: ${currentOutput}, target output: ${targetOutput}`
38+
// );
39+
// console.log(formatAs12HourClock("11.45"))
40+
41+
42+
// // Afternoon =============> assertion failed
43+
// let currentOutput2 = formatAs12HourClock("12:00");
44+
// let targetOutput2 = "12:00 pm";
45+
// console.assert(
46+
// currentOutput2 === targetOutput2,
47+
// `current output: ${currentOutput2}, target output: ${targetOutput2}`
48+
// );
49+
// console.log(formatAs12HourClock("12:00"))
50+
51+
// // Early afternoon =============> assertion passed
52+
// currentOutput2 = formatAs12HourClock("14:00");
53+
// targetOutput2 = "02:00 pm";
54+
// console.assert(
55+
// currentOutput2 === targetOutput2,
56+
// `current output: ${currentOutput2}, target output: ${targetOutput2}`
57+
// );
58+
// console.log(formatAs12HourClock("14:00"))
59+
60+
// // Mid afternoon =============> time display doesn't correspond
61+
// currentOutput2 = formatAs12HourClock("15:30");
62+
// targetOutput2 = "03:30 pm";
63+
// console.assert(
64+
// currentOutput2 === targetOutput2,
65+
// `current output: ${currentOutput2}, target output: ${targetOutput2}`
66+
// );
67+
// console.log(formatAs12HourClock("15:30"))
68+
69+
// // Towards evening ==============> time display doesn't correspond
70+
// currentOutput2 = formatAs12HourClock("17:30");
71+
// targetOutput2 = "05:30 pm";
72+
// console.assert(
73+
// currentOutput2 === targetOutput2,
74+
// `current output: ${currentOutput2}, target output: ${targetOutput2}`
75+
// );
76+
// console.log(formatAs12HourClock("17:30"))
77+
78+
// // Late night =============> assertion passed
79+
// currentOutput2 = formatAs12HourClock("23:00");
80+
// targetOutput2 = "11:00 pm";
81+
// console.assert(
82+
// currentOutput2 === targetOutput2,
83+
// `current output: ${currentOutput2}, target output: ${targetOutput2}`
84+
// );
85+
// console.log(formatAs12HourClock("23:00"))
86+
87+
588
function formatAs12HourClock(time) {
689
const hours = Number(time.slice(0, 2));
90+
const minutes = time.slice(3, 5);
791
if (hours > 12) {
8-
return `${hours - 12}:00 pm`;
92+
return `${hours - 12}:${minute} pm`;
993
}
1094
return `${time} am`;
1195
}
@@ -89,3 +173,7 @@ console.log(formatAs12HourClock("23:00"))
89173

90174

91175

176+
177+
178+
179+

0 commit comments

Comments
 (0)