Looping and adding for repeat a string problem

Tell us what’s happening:
I feel like I’ve been running into this issue with other problems. When i create a for loop such as I this, I assume that it’ll add “str” to “newstr” three times over because I’ve created the loop but it only adds it once. Can someone help em identify where I’m going wrong?

Your code so far

function repeatStringNumTimes(str, num) {
var newstr = ''
for (var i = 0; i < num; i++) {
  return newstr += str

console.log(repeatStringNumTimes("abc", 3));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36.

Challenge: Repeat a String Repeat a String

Link to the challenge:

a return statement stops the function, so once a return statement is executed the function has an output and does nothing else

1 Like