Title Case a Sentence- why my cod is not working?

Title Case a Sentence- why my cod is not working?
0

#1

Your code so far


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

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/62.0.3202.94 Safari/537.36.

Link to the challenge:


#2

This is not changing anything, because str[i] is a string and strings are immutable. If you want to make the first letter of str[i] uppercase, you need to assign it to a new variable, because toUpperCase will return a new string. The following is perfectly fine:

var firstLetter = str[i].charAt(0).toUpperCase();