I’m not sure if I’m missing something, but I believe I have a working solution for the Title Case A Sentence JavaScript challenge that isn’t being accepted by the editor.
**Your code so far**
function titleCase(str) {
let words = str.split(" ");
let sentence = "";
for (let i = 0; i < words.length; i++) {
let lower = words[i].toLowerCase();
let upper = lower[0].toUpperCase();
let eachWord = lower.replace(lower[0], upper);
sentence = sentence + eachWord + " ";
}
sentence.trim();
console.log(sentence);
return sentence;
}
titleCase("I'm a little tea pot");
titleCase("sHoRt AnD sToUt")
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36
Thank you so much, that was extremely helpful and also thanks for giving advice that will help in the future too around whether a method was mutating or non-mutating. I have never actually considered that different methods were mutating or not-mutating but it seems obvious now!