Title Case Challenge Help

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:

Well, you have this:

let lowerwords = lower.split(' ');

This means that lowerwords is an array of strings - so, it’s an array.

Then you have:

lowerwords.charAt(0)

So, you are trying to apply charAt to an array. But that is a string function. Are you sure that you want to apply that to lowerwords. As a hint, you have that index variable i for a reason.