Title Case a Sentence - FCC issue

Title Case a Sentence - FCC issue
0

#1

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");

#2

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.


#4

thanks :slight_smile: @BenGitter


#5

Thanks mate! It was helpful:)