Title Case a Sentence - FCC issue

Hello FCC coders!

I don’t know why, but FCC is not accepting this code. It works on CodeOpen. Is it the issue of FCC site?

function titleCase(str) {
  var arr=str.toLowerCase().split(' ');
  var arrNew='';
  for(var i=0; i<arr.length; i++){
    var arrI = arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
    arrNew+=arrI+' ';
  return arrNew;

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

Hey, you also add a space if there is no next word. I suppose that’s why it isn’t working. If you change return arrNew to return arrNew.trim() it should work fine.

1 Like

thanks :slight_smile: @BenGitter

Thanks mate! It was helpful:)