Basic Algorithm Scripting - Title Case a Sentence

Tell us what’s happening:
Describe your issue in detail here.
Same issue here, i have corrected the part of the code that makes some of the challenges fail and also console.logged all of them to ensure they return the correct string yet it keeps telling me am wrong. I’m confused at this point…is there only a particular method to solve this challenge? Because my method below works just fine.

  **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);
  let lower = remnant.toLowerCase();
  var final = cap + lower;
  capitalizedString += " " + final;
}
return capitalizedString;
}

console.log(titleCase("sHoRt AnD sToUt"));
  **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:

Hey,

You’ve got space in front of the string