Title Case a Sentence -- Help (SOLVED!)

Good day all! I’m stuck on level the ‘Title Case a Sentence’ challenge. Please I urgently need your help.

Here’s my code:

function titleCase(str) {

var splits = str.split(' ', 300);
var newWord = "";
for (var i = 0; i < splits.length; i++) {
    
   var lowerCase = splits[i].toLowerCase();
   var upperCase = lowerCase[0].toUpperCase();
   var capitalized = lowerCase.replace(lowerCase[0], upperCase);
   newWord +=(capitalized + " "); 
}

return newWord;
}

titleCase(“I’m a little tea pot”);
// >>> should return "I’m A Little Tea Pot"
titleCase(“sHoRt AnD sToUt”);
// >>> should return "Short And Stout"
titleCase(“HERE IS MY HANDLE HERE IS MY SPOUT”);
// >>> should return “Here Is My Handle Here Is My Spout”

They all produce the required output but the free code camp validator would not give me a pass on any of them. Please take a look at my code and give me some suggestions. Thanks

Hi,

You’re leaving a space after the result. If you remove it from the string, it will pass the tests.

Happy coding!

Thanks, will make adjustments right away.