Basic Algorithm Scripting - Repeat a String Repeat a String

Tell us what’s happening:
With this code i am getting the desired output but could not pass the test please help me out with this piece of code.

  **Your code so far**
function repeatStringNumTimes(str, num) {
  let result = " ";
for(let i=0; i<num; i++){
  result = result.concat(str);

   return result;

   return "";


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

Challenge: Basic Algorithm Scripting - Repeat a String Repeat a String

Link to the challenge:

You sure? I assume you are console logging, but sometimes that can be tricky with some minor errors. Highlight the text in the console and see if you can find the minor error.

Edit: something better to highlight it would be tossing strings around your variable "**"+variable+"**" in the log.


Do what Lego_My_Eggo suggested: It’s a small detail, but, as we know, small details make all the difference.

1 Like

The problem is you are returning a new variable “result”, but the problem wants you to make the changes in str variable itself and then return str and not some local variable.

thanks a lot, i got the required i guess i was making mistake while assigning empty string and by mistakenly i passed space within.

yes, i guess it was also the case but, by removing space from the result variable as{ let result = “”;} i got the result.
thanks, for pointing it out.

Yep, that’s issue that I encountered.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.