2018-10-10 18:03:03 -04:00
---
id: ab6137d4e35944e21037b769
title: Title Case a Sentence
isRequired: true
challengeType: 5
2019-08-28 16:26:13 +03:00
forumTopicId: 16088
2018-10-10 18:03:03 -04:00
localeTitle: Название Случайное предложение
---
## Description
2019-08-28 16:26:13 +03:00
<section id='description'>
2019-11-19 19:54:48 -05:00
Верните предоставленную строку с первой буквой каждого слова, заглавными. Убедитесь, что остальная часть слова находится в нижнем регистре. Для целей этого упражнения вы также должны использовать прописные слова, такие как «the» и «of». Н е забудьте использовать <a href="https://www.freecodecamp.org/forum/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask,</a> если вы застряли. Напишите свой собственный код.
2019-08-28 16:26:13 +03:00
</section>
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
<section id='instructions'>
2018-10-10 18:03:03 -04:00
</section>
## Tests
<section id='tests'>
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: <code>titleCase("I' ;m a little tea pot")</code> should return a string.
testString: assert(typeof titleCase("I'm a little tea pot") === "string");
- text: <code>titleCase("I' ;m a little tea pot")</code> should return <code>I' ;m A Little Tea Pot</code>.
testString: assert(titleCase("I'm a little tea pot") === "I'm A Little Tea Pot");
- text: <code>titleCase("sHoRt AnD sToUt")</code> should return <code>Short And Stout</code>.
testString: assert(titleCase("sHoRt AnD sToUt") === "Short And Stout");
- text: <code>titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")</code> should return <code>Here Is My Handle Here Is My Spout</code>.
testString: assert(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") === "Here Is My Handle Here Is My Spout");
2018-10-10 18:03:03 -04:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function titleCase(str) {
return str;
}
titleCase("I'm a little tea pot");
```
</div>
</section>
## Solution
<section id='solution'>
```js
2019-08-28 16:26:13 +03:00
function titleCase(str) {
return str.split(' ').map(word => word.charAt(0).toUpperCase() + word.substring(1).toLowerCase()).join(' ');
}
titleCase("I'm a little tea pot");
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
</section>