Hello everyone.
I am facing some difficulties with the algorithm repeat a string. Bellow is my code and I don’t know why it doesn’t return an empty string when num is smaller than 0.
function repeatStringNumTimes(str, num) {
var foo = str.repeat(num);
var empty = “”;
if (num < 0 ){
return empty;
} else {
return foo;
}
}
repeatStringNumTimes(“abc”, 3);
I try without creating a var empty but again it didn’t work.
Can someone tell me what’s wrong?