Tell us what’s happening:
I am not able to pass this problem
why was I not able to use the push method
please let me know, where mistake lies in my code??
I’m getting this error
TypeError: str1.push is not a function Your code so far
function repeatStringNumTimes(str, num) {
let str1 = ("");
if (num === +num) {
for (let i=0; i<=num; i++) {
str1.push(str);
}
} else {
return ""
}
return str1;
}
console.log(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/110.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Repeat a String Repeat a String
Did you check out the link I posted above? It has the lesson on combining strings with the + operator. I think that you should try to use that to solve this problem.