Repeat a string help

You could also use the built in repeat method.

function repeatStringNumTimes(str, num) {
  if(num < 0){
    return "";
  }
  else{
      return str.repeat(num);
}  
}

repeatStringNumTimes("abc", 3);
1 Like