Output is correct but tests fail

Here is my code for titleCase function.
The code returns a string and the string is correct. I checked all tests by console.log(copy).
Maybe I’m missing something. I would appreciate help.

  **Your code so far**

function titleCase(str) {
let arrayOfStrings = [];
arrayOfStrings = str.split(' ');
let copy = '';
for(let i=0;i<arrayOfStrings.length;i++){
  for(let j=0;j<arrayOfStrings[i].length;j++){
    if(j===0){
        copy += arrayOfStrings[i][j].toUpperCase();
    }else{
      copy += arrayOfStrings[i][j].toLowerCase();
    }
  }
  copy +=  '  ';
}
return copy;
}

titleCase("sHoRt AnD sToUt");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36.

Challenge: Title Case a Sentence

Link to the challenge:

It looks like you may have an extra space at the end of your output.

That was it. Thank u !

1 Like