Hello another post here. I’m working on the Title Case a Sentence exercise. I was able to came up to this solution using a for loop. First I created a variable to lowecase the string, then the result of this variable will be store in an another variable separating/splitting the string into array of words. Once I got my array of words, I made the for loop using the latest variable to iterate each array. I think this has worked so far but when I pass the string into the function, the result duplicates the first letter of each array both lower case and upper case. Did I miss something in here just to get the result of the upper case?
function titleCase(str){
var lowerCase = str.toLowerCase();
eachWord = lowerCase.split(" ");
for (i = 0; i < eachWord.length; i++){
eachWord[i] = eachWord[i].charAt(0).toUpperCase()+eachWord[i].split(1)
}
return eachWord.join(" ");
}
titleCase (“JavaScript is hard.”);
