I’m trying to figure out after spliting the string into an array then lowercase the string, after that how to use { toUpperCase} with replace() method.
then formulating a for loop to iterate through the array and finally joining them into one string.
You can add a callback function as the second argument to the replace-method. You can read about it on MDN String.prototype.replace. Their example is fairly complex, but in the end you can pass the first character and return it in uppercase.
function titleCase(str) {
let lowerCase = str.toLowerCase().split(" ");
let upperCase = lowerCase.replace(/(0)/i, lowerCase.toUpperCase())
for( let i = 0; i > lowerCase.length; i++){
;
}
}
titleCase("I'm a little tea pot");
I wanted to use Regexp to capitalize the first letter of the string, either use regexp or charAt(), and then from there join the array using a for loop.
I am abit lost there on how to use either of those methods. and how the for loop comes in.
But you’re trying to replace something in lowerCase, that’s an array.
You first have to go into each item of lowerCase.
// iterate through lowerCase (e.g. for loop)
// make first character uppercase (e.g. replace method)
// return item
// join all strings of array back together