Title Case a Sentence2

Tell us what’s happening:

Your code so far

function titleCase(str) {
   var  str2;
  for(var i=0; i<str.length; i++)
        str2 = str.replace(str[i],str[i].toUpperCase()); 
      if(str[i]==' ')
      str2 = str.replace(str[i+1],str[i+1].toUpperCase());
  return str2;

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/60.0.3112.113 Chrome/60.0.3112.113 Safari/537.36.

Link to the challenge:

You forgot to fill out the “Tell us what’s happening” section. Please describe the problem that you are having and what you have tried so far to resolve it.