Repeat a String - Am I doing something wrong?


I solved the exercise from " Basic Algorithm Scripting: Repeat a String Repeat a String". This is my code:

function repeatStringNumTimes(str, num) {
  fstr = ""
  for (let i = 0; i < num; i++){
    fstr += str
  return fstr;

repeatStringNumTimes("abc", 3);

The problem is that the program doesn’t accept my answer. I would like to know if I am making a mistake.


You need to declare this.

1 Like

@nix You have to declare fstr using let or var Happy Coding! :smile:

1 Like