Title Case A Sentence - Works in Console but Fails Test

Hi!
The following code seems to work in the Google Chrome developer console, but does not pass the test on the FCC console. What am I doing wrong?
Thanks in advance!

function titleCase(str) {
  let newStr = str.toLowerCase();
  let strArr = newStr.match(/[\w']+/ig);
  let solutionString = "";
  for (var i = 0; i<strArr.length; i++){
    let firstLetter = strArr[i].replace(strArr[i][0],strArr[i][0].toUpperCase());  solutionString += firstLetter + " ";
  
  }
  console.log(solutionString);
  return solutionString;
}



titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");

Please, post the link to the challenge.

Sorry - forgot to include this:

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence

You are sticking an extra space on the end.

2 Likes