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
|
|
|
---
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --description--
|
|
|
|
|
2018-10-04 14:37:37 +01:00
|
|
|
Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
|
2020-11-27 19:02:05 +01:00
|
|
|
|
2018-10-04 14:37:37 +01:00
|
|
|
For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --hints--
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`titleCase("I'm a little tea pot")` should return a string.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(typeof titleCase("I'm a little tea pot") === 'string');
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`titleCase("I'm a little tea pot")` should return `I'm A Little Tea Pot`.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(titleCase("I'm a little tea pot") === "I'm A Little Tea Pot");
|
2018-10-04 14:37:37 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`titleCase("sHoRt AnD sToUt")` should return `Short And Stout`.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(titleCase('sHoRt AnD sToUt') === 'Short And Stout');
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")` should return `Here Is My Handle Here Is My Spout`.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
titleCase('HERE IS MY HANDLE HERE IS MY SPOUT') ===
|
|
|
|
'Here Is My Handle Here Is My Spout'
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
2018-10-04 14:37:37 +01:00
|
|
|
|
|
|
|
```js
|
|
|
|
function titleCase(str) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
titleCase("I'm a little tea pot");
|
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --solutions--
|
2018-10-04 14:37:37 +01:00
|
|
|
|
|
|
|
```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");
|
|
|
|
```
|