Repeat a String Repeat a String need help

Repeat a String Repeat a String need help
0

#1

Tell us what’s happening:
I got every word to double except abc 3 times and abc 4 times. I tried manipulating the loops but every time I do I get less green checks.

Your code so far


function repeatStringNumTimes(str, num) {
  // repeat after me
  var word = str.split('');
  var strings = '';

for(var k = 0; k < word.length; k++){
    for(var i = 0; i < num; i++){
      strings += word[k];
    }
  }
  

  return strings;
}

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/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/repeat-a-string-repeat-a-string


#2

have you considered writing a single for loop for this?


#3

Here’s a really important skill with programming: take your hands off the keyboard and grab a pen and paper. Walk through every line of code and write down what happens. This includes each individual action within the loop (each iteration of the loop, not just “goes through the array and…”). On each line, what is strings? What is k? What is i? What is word[k]?


#4
function repeatStringNumTimes(str, num) {
  // repeat after me
  //var word = str.split('');
  var strings = '';

for(var k = 0; k < num; k++){
    strings += str;
  }
  

  return strings;
}

repeatStringNumTimes("abc", 3);```

heres the code that works, thank you for the feedback after I went through line for line I realized I didn’t need to split the string up.