Title Case a Sentence with substring

Title Case a Sentence with substring
0.0 0


Tell us what’s happening:
I don not know what it is wrong with my code. every thing look fine but went i run it it only checks right that it is a string.help me please.

Your code so far

function titleCase(str) {
  var a = str.toLowerCase().split(" "); 
  var f = " ";
  for(var i = 0;i < a.length;i++){
  f +=  a[i].substring(0,1).toUpperCase() + a[i].substring(1,a[i].length) + " ";
  return f;

titleCase("I'm A Little Tea Pot");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36.

Link to the challenge:


I’m not totally sure, but i think the problem is the space character you add at the end of every word. The last word is followed by a space char which does not exists in the original string :confused:


a[i].substring(0,1).toUpperCase() + a[i].substring(1,a[i].length) + " ";

if you have array a = [h,e,l,l,o]
so a[0] equal ‘h’