Skip to content

Commit e76a59c

Browse files
committed
update the function to hundle invalid input.
1 parent 550f44d commit e76a59c

File tree

1 file changed

+3
-0
lines changed
  • Sprint-3/3-mandatory-practice/implement

1 file changed

+3
-0
lines changed

Sprint-3/3-mandatory-practice/implement/repeat.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
function repeat(word, times) {
2+
if (times < 0) {
3+
throw new Error("Times must be a non-negative integer");
4+
}
25
return word.repeat(times);
36
}
47
console.log(repeat("hello", 3)); // The output should be "hellohellohello"

0 commit comments

Comments
 (0)