Title Case a Sentence7

Tell us what’s happening:
My code passes all the test when I console.log(), but when I run the test it will not pass. Could anyone suggest what I did wrong?

Your code so far

function titleCase(str) {
  let myString = '';
  let lowerCaseStr = str.toLowerCase();
  let splitStr = lowerCaseStr.split(' ');
  for(let i = 0; i < splitStr.length; i++){
    myString += splitStr[i].replace(splitStr[i].charAt(0), function(str){
      let cap = str.toUpperCase();
      return cap;
    myString += ' ';
  return myString;

titleCase("sHoRt AnD sToUt");

Link to the challenge:

Pretty close!

You are adding an extra space at the end of each returned sentence.


Thank you so much! That helped a lot!