Help -- Basic Algorithm Scripting: Title Case a Sentence

Tell us what’s happening:

I’ve been using Replit for my workings and then moving my answers over to FCC. This solution seems to be satisfying all of the different test cases when I try them on Replit, but it isn’t working on FCC. Can someone explain why?

Your code so far

function titleCase(str) {
var newArray = str.split(" ")
var finalString = " ";
for (var i = 0; i < newArray.length; i++) {
  finalString += newArray[i].charAt(0).toUpperCase() + newArray[i].slice(1).toLowerCase() + " ";
} return finalString;

titleCase("I'm a little tea pot");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36.

Challenge: Title Case a Sentence

Link to the challenge:

You’re adding a space to the beginning and ending of the sentence.