This is my code so far.
function titleCase(str) {
var array = str.toLowerCase().split(" ");
var new_array = "";
var newword = "";
for (let i = 0; i < str.length; i++) {
newword = array[i][0].toUpperCase() + array[i].substring(1);
new_array += " " + newword.slice();
}
return new_array;
}
titleCase("I'm a little tea pot");
The console.log returns the correct string. However everytime I try and submit my answer, I am told the “Cannot read property ‘0’ of undefined”.