Practice in using learned methods

Character case

Suppose we have some variable with text:

let str = 'london';

Let's convert the first character of this string to uppercase:

let str = 'london'; let result = str.slice(0, 1).toUpperCase() + str.slice(1); console.log(result); // shows 'London'

Convert the last character of the string to uppercase.

Convert the first 2 characters of the string to uppercase.

Let there be a string whose first character is in uppercase, for example, like this:

let str = 'London';

Convert the first character of the string to lowercase.

Words in a string

Suppose we have some variable with text consisting of several words:

let str = 'word1 word2 word3';

Let's write a code that converts the first letter of each word to uppercase. I will immediately give a solution with comments:

let str = 'word1 word2 word3'; // Let's split the string into an array of words: let words = str.split(' '); for (let i = 0; i < words.length; i++) { // Convert each word to uppercase: words[i] = words[i].slice(0, 1).toUpperCase() + words[i].slice(1); } // Merge the array back into a string: let result = words.join(' '); console.log(result); // shows 'Word1 Word2 Word3'

On your own, without looking into my code, repeat my solution to the described problem.

Convert the string 'var_test_text' to 'VarTestText'.

The code you write should work for any strings of this type (that is, strings where words are separated by underscores).

Modify the previous problem so that the first letter of the new string is in lowercase.

Reverse a string

Suppose we have some variable with a string:

let str = '12345';

Let's reverse the characters of this string:

let str = '12345'; let result = str.split('').reverse().join(''); console.log(result); // shows '54321'

Given a string with words. Write a script that will rearrange the words in this string in reverse order.

enru