JS Built-ins
StringString.prototype.charAtintermediate

String.prototype.charAt() β€” middle character

πŸ“– Usage Example
const str = 'Hello'
str.charAt(0)    // β†’ 'H'
str.charAt(1)    // β†’ 'e'
str.charAt(99)   // β†’ ''

Use charAt() to get the character at a specific index, returning an empty string for out-of-bounds positions.

String.prototype.charAt() β€” Middle

Challenge: Implement midChar(str) using .charAt() to return the middle character of an odd-length string.

midChar('hello') // β†’ 'l'
midChar('abc')   // β†’ 'b'
πŸ’‘ Hints (1)
  • β€’ `Math.floor(str.length / 2)` gives the middle index for any length.