Q:

Write a JavaScript program to create a new string of specified copies (positive number) of a given string

0

Write a JavaScript program to create a new string of specified copies (positive number) of a given string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function string_copies (str, n) 
{
  if (n < 0)
    return false;
  else
  return str.repeat(n);
}
console.log(string_copies("abc", 5));
console.log(string_copies("abc", 0));
console.log(string_copies("abc", -2));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now