Tell us what’s happening:
I want the for loop to run three times(or as many times is specified in the second parameter of the function). For some reason it is not working.
I want to concatenate the string as many times it runs in the for loop.
Your code so far
function repeatStringNumTimes(str, num) {
var str1 = str ;
if(num < 0){
return "" ;
}else{
for(var i = 1 ; i<= num ; i++)
{
var str2 =str.concat(str1);
}
console.log(str2);
}
}
repeatStringNumTimes("abc", 3);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
.
Challenge: Repeat a String Repeat a String
Link to the challenge: