Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Title Case

Data Structures, Operators & Stringseasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 128: Working With Strings - Part 1

Implement `titleCase(s)` returning `s` with the first letter of each space-separated word capitalized.

Sample tests

Input: titleCase("hello world")
Output: "Hello World"
Input: titleCase("a b c")
Output: "A B C"

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Indexing w[0] on an empty word throws; guard empty words.
  • Losing the original spacing if you split and join carelessly.

Learning resources

  • MDN: String
Approach & explanation (try first)

Splitting on spaces lets you uppercase each word's first letter and rejoin, with a guard for empty segments.

Loading...
⌘/Ctrl + Enter

Run your code to see results.