I've been trying for the last hours to understand why my code is not working well. Instead of capitalizing only the first letters of each item in the array my code capitalizes all the letters in the array.
function titleCase(str) {
str = str.toLowerCase().split(' ');
for (var i = 0; i < str.length; i++){
str[i] = str[i].split(' ');
str[i][0] = str[i][0].toUpperCase();
str[i] = str[i].join(' ');
}
return str.join(' ');
}
titleCase("I'm a little tea pot");