Build a Title Case Converter - Build a Title Case Converter

Tell us what’s happening:

Hi When I console log the tests the correct answers is being displayed but I’m not passing tests 4, 5, 6 , not sure if have just not used the code that is wanted or if there is something in the existing code

Your code so far

function titleCase(str) {
  let first = str.toLowerCase();
  let splits = first.split(" ");
  let upper = [];
  let result =[];
  for (let i = 0; i < splits.length; i++) {
   upper.push(splits[i][0].toUpperCase() + splits[i].substr(1) + " ");
   result = upper;
 }
  return result.join('');
};
console.log(titleCase("sHoRt AnD sToUt"));
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
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/147.0.0.0 Safari/537.36 Edg/147.0.0.0

Challenge Information:

Build a Title Case Converter - Build a Title Case Converter

Hi @paulscrafton,

Do you even need the result array? And since join() can add back the space, do you really need to concatenate a space to the value pushed into upper?

Happy coding!