Skip to content

Commit 92cdff7

Browse files
committed
Made fix to catch cases of empty strings, non-string inputs, check for integers
1 parent 508e466 commit 92cdff7

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ function pad(num) {
1010
return stringNum;
1111
}
1212
}
13-
function formatAs12HourClock(time) {
13+
function formatAs12HourClock(time = "") {
14+
if (typeof time != "string") {
15+
return "Not a valid format"; //check if time is a string
16+
}
1417
if (
1518
(time.indexOf(":") === -1 && time.indexOf(".") === -1) ||
1619
(time.indexOf(":") !== -1 && time.indexOf(".") !== -1)
@@ -53,7 +56,9 @@ function formatAs12HourClock(time) {
5356
hours >= 24 ||
5457
hours < 0 ||
5558
minutes >= 60 ||
56-
minutes < 0
59+
minutes < 0 ||
60+
hours % 1 != 0 ||
61+
minutes % 1 != 0
5762
) {
5863
return "Not a valid time";
5964
} //check if numbers are valid

0 commit comments

Comments
 (0)