Basic Algorithm Scripting - Title Case a Sentence

I came up with the solution below, and testing it gives me the desired output, but it won’t pass when I submit it. What am I missing? Or am I only supposed to answer according to principal?

  **Your code so far**
function titleCase(str) {
let arr = str.split(" ");
let outStr = ""
//console.log(arr)
for (let i = 0; i < arr.length; i++){
  let str1 = arr[i].charAt(0).toUpperCase() + arr[i].slice(1).toLowerCase();
  //console.log(str1)
  outStr += str1 + " ";
}
//console.log(outStr);
return outStr;
}

titleCase("I'm a little tea pot");
titleCase("sHoRt AnD sToUt");
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/105.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Link to the challenge:

the test case is failing because you are adding space at last index also.
outStr += str1 + " ";
this will result as below string
"I’m A Little Tea Pot " whereas it should be “I’m A Little Tea Pot”.
just a shuttle difference :upside_down_face:

1 Like

:rofl: :rofl: :rofl:Now that you mention it, it looks lousy

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