Code is running perfectly fine but test case are not passing

function titleCase(str) {
  var word = str.split(' ');
  var max='';
  var line ='';
  for(let i=0; i<word.length; i++){
    max= word[i].charAt(0).toUpperCase() + word[i].slice(1).toLowerCase();
    line = line.concat(' ', max);
  }
//  console.log(line)
  return line;
}
titleCase("I'm a little tea pot");

this is my code of Title case challenge. I tried running in my compiler and used console.log to try in window and it was running totally fine, but still not able to pass test cases.https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence

There’s small detail that’s easy to miss. Uncomment the printing out line to console and add console.log(str) above or below. See how they compare side by side.

1 Like

I am able to find the problem , I am adding space in the end of my string. So probably fault in my logic.