← Back to challenges

Capitalize the First Letter of Each Word

JavaScriptHardformattingstringsloopsregex

Instructions

Create a function that takes a string as an argument and converts the first character of each word to uppercase. Return the newly formatted string.

Examples

makeTitle("This is a title") ➞ "This Is A Title"

makeTitle("capitalize every word") ➞ "Capitalize Every Word"

makeTitle("I Like Pizza") ➞ "I Like Pizza"

makeTitle("PIZZA PIZZA PIZZA") ➞ "PIZZA PIZZA PIZZA"

Notes

  • You can expect a valid string for each test case.
  • Some words may contain more than one uppercase letter (see example #4).
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Equality of 3 Values