Title Case a Sentence confusion

Hi everyone!

So I’m trying to solve the Title Case a Sentence problem and I’ve written some code for it, but it’s not outputting a joined string and I’m not sure why.

Here’s my code:

function titleCase(str) {
  var stringArray = str.toLowerCase().split(" ");
  for (var i = 0; i < stringArray.length; i++) {
   return stringArray[i].charAt(0).toUpperCase() + stringArray[i].slice(1);
  }
  return stringArray.join();
}

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

Thank you for your help!

Thanks so much for your help! I changed my code, but now I get an error message that my .join() method is not a function / undefined. I don’t know how it’s undefined.

function titleCase(str) {
  var stringArray = str.toLowerCase().split(" ");
  for (var i = 0; i < stringArray.length; i++) {
   str = stringArray[i].charAt(0).toUpperCase() + stringArray[i].slice(1);
  }
  return str.join(" ");
}

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