Code works but doesn't pass the test. Can't figure out why

Code works but doesn't pass the test. Can't figure out why
0

#1
function titleCase(str) {
  var split = str.split(" ");
  var text = "";
  for (i = 0; i < split.length; i++) {
    text += split[i].charAt(0).toUpperCase() + split[i].slice(1).toLowerCase() + " ";
  }
    return text;
}
titleCase("I'm a little tea pot");

#2

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3

The string you return at the end has a space character. For example:

titleCase("I'm a little tea pot"); // yields 'I\'m A Little Tea Pot ' <= See the space at the end