Worked through this for a couple of hours with some stack exchange and google look ups and produced the code below. I keep getting the error message that lowerwords.charAt is not a function. Gave up and looked at the answers and none approach what I’m trying to do here. Any help or tip would be great!
Your code so far
function titleCase(str) {
let lower = str.toLowerCase();
let lowerwords = lower.split(' ');
let newStr = '';
for (let i = 0; i < lowerwords.length; i++) {
let cap = lowerwords.charAt(0).toUpperCase() + lowerwords.slice(1);
return newStr + cap;
}
}
console.log(titleCase("I'm a little tea pot"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36
.
Challenge: Title Case a Sentence
Link to the challenge: