Test runs fails, even after the output is same as required? (JavaScript -Basic Algorithm Scripting - Title Case a Sentence)

function titleCase(str) {
  str = str.toLowerCase();
  let regx = /[a-z']+/g;
  let words = str.match(regx);
  let modifiedStr = "";
  for (let i = 0; i < words.length; i++) {
    modifiedStr += words[i].replace(words[i][0], words[i][0].toUpperCase()) + " ";
  }
   return modifiedStr;
}
console.log(titleCase("I'm a little tea pot"));
console.log(titleCase("sHoRt AnD sToUt"));

output> I’m A Little Tea Pot
output> Short And Stout

Please provide a link to the challenge.

I assume because you add a space at the end of the loops, your output will also have an excess space at the end.

1 Like

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