We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 92453f8 commit a1f992aCopy full SHA for a1f992a
Sprint-2/5-stretch-extend/format-time.js
@@ -4,7 +4,12 @@
4
5
function formatAs12HourClock(time) {
6
const hours = Number(time.slice(0, 2));
7
- const minutes = time.slice(3, 5);
+ const minutes = time.slice(-2);
8
+
9
+ // Basic validation (fix bug: invalid hour values)
10
+ if (hours < 0 || hours > 23) {
11
+ return "Invalid time";
12
+ }
13
14
// If midnight (00), convert to 12 am
15
if (hours === 0) {
@@ -37,4 +42,4 @@ const targetOutput2 = "11:00 pm";
37
42
console.assert(
38
43
currentOutput2 === targetOutput2,
39
44
`current output: ${currentOutput2}, target output: ${targetOutput2}`
40
-);
45
+);
0 commit comments