Skip to content

Commit 93d9cb6

Browse files
committed
Add implementation for the function repeat
1 parent ed1a393 commit 93d9cb6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Sprint-3/2-practice-tdd/repeat.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
function repeat() {
2-
return "hellohellohello";
1+
function repeat(valueToRepeat, numOfTimes) {
2+
let repeatedValue = "";
3+
if (numOfTimes > 0) {
4+
for (let i = 0; i < numOfTimes; i++) {
5+
repeatedValue += valueToRepeat;
6+
}
7+
} else if (numOfTimes === 0) {
8+
repeatedValue = "";
9+
}
10+
else {
11+
repeatedValue = "Negative number invalid";
12+
}
13+
return repeatedValue;
314
}
415

516
module.exports = repeat;

0 commit comments

Comments
 (0)