Basic Algorithm Scripting - Title Case a Sentence

Tell us what’s happening:
Describe your issue in detail here.
I used the code below to convert all the first letters of a string to upper case letters but when i submitted the challenge, i noticed that the second part of my challenge was marked as wrong despi5te the fact that when i console.logged the function, the string printed was the same with the string that i was supposed to return in the function. Please what could causse this?

  **Your code so far**
function titleCase(str) {
var capitalizedString = "";
var strArr = str.split(" ");
for(let i = 0; i < strArr.length; i++){
  var word = strArr[i];
  var first = word.charAt(0);
  var cap = first.toUpperCase();
  let remnant = word.slice(1);
  var final = cap + remnant;
  capitalizedString += " " + final;
}
return capitalizedString;
}

console.log(titleCase("I'm a little tea pot"));
  **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:

@charlieboy1 Hey,
If you try a

console.log("this is a test string") ;

(can be anything) you can see where the problem is. For an example,

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

If you call the function with the above argument and add a console.log() just below the function your output will be like this,

this is a test string
 I'm a Little Tea Pot

You can clearly see the difference, which is there is a space before the I'm of the output.
Where that space is coming from? You can see that clearly in your code where you add the first part of the sentence to the capitalizedString.