|
1 |
| -//Part Three section one |
| 1 | +// Part Three section one |
2 | 2 |
|
3 | 3 | let language = 'JavaScript';
|
4 | 4 |
|
5 |
| -//1. Use string concatenation and two slice() methods to print 'JS' from 'JavaScript' |
| 5 | +// 1. Use string concatenation and two slice() methods to print 'JS' from 'JavaScript' |
| 6 | +let abbreviation = language.slice(0, 1) + language.slice(4, 5); |
| 7 | +console.log(abbreviation); // Prints 'JS' |
6 | 8 |
|
7 |
| -//2. Without using slice(), use method chaining to accomplish the same thing. |
| 9 | +// 2. Without using slice(), use method chaining to accomplish the same thing. |
| 10 | +abbreviation = language.charAt(0) + language.charAt(4); |
| 11 | +console.log(abbreviation); // Prints 'JS' |
8 | 12 |
|
9 |
| -//3. Use bracket notation and a template literal to print, "The abbreviation for 'JavaScript' is 'JS'." |
| 13 | +// 3. Use bracket notation and a template literal to print, "The abbreviation for 'JavaScript' is 'JS'." |
| 14 | +console.log(`The abbreviation for '${language}' is '${language[0]}${language[4]}'.`); |
10 | 15 |
|
11 |
| -//4. Just for fun, try chaining 3 or more methods together, and then print the result. |
| 16 | +// 4. Just for fun, try chaining 3 or more methods together, and then print the result. |
| 17 | +let funResult = language.toLowerCase().replace('java', 'ecma').toUpperCase(); |
| 18 | +console.log(funResult); // Prints 'ECMASCRIPT' |
12 | 19 |
|
13 |
| -//Part Three section Two |
14 |
| - |
15 |
| -//1. Use the string methods you know to print 'Title Case' from the string 'title case'. |
| 20 | +// Part Three section two |
16 | 21 |
|
| 22 | +// 1. Use the string methods you know to print 'Title Case' from the string 'title case'. |
17 | 23 | let notTitleCase = 'title case';
|
| 24 | +let titleCase = notTitleCase |
| 25 | + .split(' ') |
| 26 | + .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) |
| 27 | + .join(' '); |
| 28 | +console.log(titleCase); // Prints 'Title Case' |
0 commit comments