Hey everybody,
I know that this is certainly not the most efficient solution for this, but I am a beginner and am struggling through it. Right now I have it where all of the words that are passed through the function are title cased. However, whenever I try to return (or even console.log) titleCaseArray, I get "cannot read property β0β of undefined. Anybody know why that is?
Thanks,
David
Your code so far
function titleCase(str) {
var arrayOfStrings = str.toLowerCase().split(" ");
var titleCaseArray = [];
for (i = 0; i <= str.length; i++) {
var firstLetter = arrayOfStrings[i][0];
var restOfWord = arrayOfStrings[i].slice(1, arrayOfStrings[i].length);
var bigCase = firstLetter.toUpperCase() + restOfWord;
titleCaseArray.push(bigCase);
}
return titleCaseArray;
}
titleCase("I'm a little tea pot");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.73 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/title-case-a-sentence