--- id: ab6137d4e35944e21037b769 title: Title Case a Sentence localeTitle: Título Caso una oración isRequired: true challengeType: 5 --- ## Description
Devuelva la cadena provista con la primera letra de cada palabra en mayúscula. Asegúrese de que el resto de la palabra esté en minúscula. A los efectos de este ejercicio, también debe poner mayúsculas en las palabras de conexión como "el" y "de". Recuerda usar Read-Search-Ask si te atascas. Escribe tu propio código.
## Instructions
## Tests
```yml tests: - text: ' titleCase("I'm a little tea pot") debería devolver una cadena.' testString: 'assert(typeof titleCase("I"m a little tea pot") === "string", "titleCase("I'm a little tea pot") should return a string.");' - text: ' titleCase("I'm a little tea pot") debería devolver I'm A Little Tea Pot ' testString: 'assert(titleCase("I"m a little tea pot") === "I"m A Little Tea Pot", "titleCase("I'm a little tea pot") should return I'm A Little Tea Pot.");' - text: titleCase("sHoRt AnD sToUt") debe devolver Short And Stout . testString: 'assert(titleCase("sHoRt AnD sToUt") === "Short And Stout", "titleCase("sHoRt AnD sToUt") should return Short And Stout.");' - text: titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") debería regresar. Here Is My Handle Here Is My Spout . testString: 'assert(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") === "Here Is My Handle Here Is My Spout", "titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") should return Here Is My Handle Here Is My Spout.");' ```
## Challenge Seed
```js function titleCase(str) { return str; } titleCase("I'm a little tea pot"); ```
## Solution
```js function titleCase(str) { return str.split(' ').map(word => word.charAt(0).toUpperCase() + word.substring(1).toLowerCase()).join(' '); } titleCase("I'm a little tea pot"); ```