Repeat a String Repeat a String Alexoid

Tell us what’s happening:
what’s wrong in my code?
i test it and does what it is asked

Your code so far


function repeatStringNumTimes(str, num) {
 if(num>0){
   for(let n=1; n<=num; n++){
     return str;
   }
 }else{
   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/75.0.3770.142 Safari/537.36 OPR/62.0.3331.116.

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

Hi @Alexoid, welcome on the forum.
When you use the return statement, the execution of the function stops and the flow goes back to whatever called it.
In your case, the return str; in the for loop makes the execution stop at the first iteration, when the counter is still at one.
The return should go after you have done all the iterations of the for loop, returning the result string made by the repetition not the initial string.