Task:
Create a function that turns a string into a Mexican Wave. You will be passed a string and you must return that string in an array where an uppercase letter is a person standing up.
let mexicanWave = str.slice(0, i) + str[i].toUpperCase() + str.slice(i + 1);
Above code aims to create a string where one character is capitalized (turned into uppercase), and the rest of the string is unchanged.
Let's break it down:
str.slice(0, i)
: This is creating a new string that includes the characters from the start of the original string (str
) up to but not including thei
th character.slice
is a method provided by JavaScript's String prototype that returns a portion of the string.str[i].toUpperCase()
: This is getting thei
th character from the original string (str[i]
) and capitalizing it using thetoUpperCase
method, also provided by the String prototype.str.slice(i + 1)
: This is creating a new string that includes all characters from the original string (str
) starting from the character after thei
th character.The
+
operators are then concatenating these three strings together to form a new string. Thei
th character of this new string is capitalized, and the rest of the string is the same as the original string.