Title Case a Sentence: Expected matches Actual

Title Case a Sentence: Expected matches Actual
0

#1

Tell us what’s happening:
The output looks correct, I know the solution is not optimal however I’m wondering why the tests are not passing?
Because what’s showing in the console does indeed match the expected outcome.

Thanks

Your code so far


function titleCase(str) {
  var toLower = str.toLowerCase().split(' ');
  var newStr = '';
  for (var i = 0; i < toLower.length; i++){
    
newStr += toLower[i].replace(toLower[i].charAt(0),  toLower[i].charAt(0).toUpperCase());
    newStr += ' ';
  }
  console.log(newStr);
  return newStr;
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36.

Link to the challenge:


#2

It’s failing because of this:

newStr += ’ ’

You’re adding a space after every single word, including the last word. You can’t see it, but it’s there after the last word, which means instead of returning “I’m A Little Teapot” you’re actually returning "I’m A Little Teapot ".