Tell us what’s happening:
Hello ! someone can explain me clearly why we can put this =>
let newArr = “”;
while (num > 0) {
newArr += str;
num- -;
} return newArr;
and can’t put this ? =>
let newArr = “”;
while (num < 0) {
newArr += str;
num++;
}
return newArr;
I understand why the first solution works but I don’t know why the second one did not work.
**Your code so far**
function repeatStringNumTimes(str, num) {
/*let newArr = "";
while (num < 0) {
newArr += str;
num++;
}
return newArr; */
let arr = [];
while (arr.length < num) {
arr.push(str);
}
return arr.join('');
}
repeatStringNumTimes("abc", 3);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36
.
Challenge: Repeat a String Repeat a String
Link to the challenge: