2018-10-04 14:37:37 +01:00
|
|
|
---
|
|
|
|
id: ab6137d4e35944e21037b769
|
|
|
|
title: Title Case a Sentence
|
|
|
|
challengeType: 5
|
2019-07-31 11:32:23 -07:00
|
|
|
forumTopicId: 16088
|
2018-10-04 14:37:37 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
|
|
|
<section id='description'>
|
|
|
|
Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
|
|
|
|
For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id='instructions'>
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
2018-10-20 21:02:47 +03:00
|
|
|
- text: <code>titleCase("I'm a little tea pot")</code> should return a string.
|
2019-07-24 01:47:32 -07:00
|
|
|
testString: assert(typeof titleCase("I'm a little tea pot") === "string");
|
2018-10-20 21:02:47 +03:00
|
|
|
- text: <code>titleCase("I'm a little tea pot")</code> should return <code>I'm A Little Tea Pot</code>.
|
2019-07-24 01:47:32 -07:00
|
|
|
testString: assert(titleCase("I'm a little tea pot") === "I'm A Little Tea Pot");
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: <code>titleCase("sHoRt AnD sToUt")</code> should return <code>Short And Stout</code>.
|
2019-07-24 01:47:32 -07:00
|
|
|
testString: assert(titleCase("sHoRt AnD sToUt") === "Short And Stout");
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: <code>titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")</code> should return <code>Here Is My Handle Here Is My Spout</code>.
|
2019-07-24 01:47:32 -07:00
|
|
|
testString: assert(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") === "Here Is My Handle Here Is My Spout");
|
2018-10-04 14:37:37 +01: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
|
|
|
|
function titleCase(str) {
|
|
|
|
return str.split(' ').map(word => word.charAt(0).toUpperCase() + word.substring(1).toLowerCase()).join(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
titleCase("I'm a little tea pot");
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|