Won't accept my code - Title Case a Sentence

Please help, why can’t the challenge accept my code? I know my code is way too long compared to the provided solutions, but my console provides the same output.

function titleCase(str) {
  let splitStr = str.split(" ");
  let upperArr = [];
  let lowerArr = [];
  let newTitle = ""
  for (let i = 0; i < splitStr.length; i++) {
      lowerArr.push(splitStr[i].toLowerCase());
      upperArr.push(splitStr[i][0].toUpperCase());
      newTitle += lowerArr[i].replace(/./, upperArr[i]);
      newTitle += " ";
  }
  return newTitle;
}

console.log(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/119.0.0.0 Safari/537.36 Edg/119.0.0.0

Challenge Information:

Basic Algorithm Scripting - Title Case a Sentence

Oh, the space at the end of the string maybe?

1 Like

Yep. Try testing your function with the following:

console.log("[", titleCase("I'm a little tea pot"), "]");

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.