JS Built-ins
← String100 / 195
StringString.prototype.padStartintermediate

String.prototype.padStart() β€” fixed-width number formatting

πŸ“– Usage Example
'5'.padStart(3, '0')       // β†’ '005'
'hi'.padStart(5, '-')     // β†’ '---hi'
'hello'.padStart(3)       // β†’ 'hello'

Use padStart() to pad the beginning of a string with a fill character until it reaches the target length.

String.prototype.padStart() β€” Fixed-Width Formatting

Zero-padding is great for time values like hours and minutes.

Challenge: Implement formatTime(h, m) that formats hours and minutes as HH:MM.

formatTime(9, 5)  // β†’ '09:05'
formatTime(12, 0) // β†’ '12:00'
πŸ’‘ Hints (1)
  • β€’ Use `String(h).padStart(2, "0")` for hours and the same for minutes.