JS Built-ins
← String104 / 195
StringString.prototype.repeatbeginner

String.prototype.repeat() β€” long repetition

πŸ“– Usage Example
'ab'.repeat(3)    // β†’ 'ababab'
'-'.repeat(5)     // β†’ '-----'
'x'.repeat(0)    // β†’ ''

Use repeat() to create a new string with the original repeated a specified number of times.

String.prototype.repeat() β€” Large Count

You can repeat a string many times. The result length is str.length * count.

Challenge: Implement buildLine(char, n) that builds a line of n identical characters.

buildLine('=', 10) // β†’ '=========='
buildLine('ab', 4) // β†’ 'abababab'
πŸ’‘ Hints (1)
  • β€’ The resulting string length will be `char.length * n`.