Hey guys decided to use while to do this one, but it’s not working out. What am I doing wrong?
Your code so far
function repeatStringNumTimes(str, num) {
var finalResult = ""; //initialize string to hold result
while (num > 0) { //repeat finalResult.push(str) while num is positive
return finalResult.push(str);
num--; // subtract num by 1
} else {
return ""; // else return empty string
}
}
console.log(repeatStringNumTimes("abc", 3));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36
.
Challenge: Repeat a String Repeat a String
Link to the challenge: