-1

so I am very new to js and I'm having a really hard time comprehending the language. Could anyone take 5 to look at this code and tell me why my function isn't working...? The goal is to create a function that duplicates a string by the number inputted into the function.

function repeatString(string, num) {
return string*num
}
var output=repeatString("Hello!",2);
console.log(output);

1 Answers1

1

You could simply call the repeat method:

function repeatString(string, num) {
    return string.repeat(num);
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350