Tell us what’s happening:
hi im unsure of how to capitalize each letter now that i have each word in an array.
also in general i feel the challenges are paced wrongly (?)
im using functions i haven’t learnt before in the earlier parts in order to solve the challenges posted in this portion of the curriculum… is this normal? or am doing all these challenges wrongly?
i feel logically i can understand how to solve the challenge but i lack the “tools” to…?
is my approach to learning javascript wrong? thank you!
Your code so far
function titleCase(str) {
let strLower = str.toLowerCase();
let strLowerArr = strLower.split(" ");
for (let i=0; i<strLowerArr.length; i++)
{
strLowerArr[i][0].toUpperCase();
}
let ans = strLowerArr.join(" ");
return ans;
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36.
In general I’ve found that the freeCodeCamp challenges can stretch the limits of what you have been taught, but the necessary tools have usually been introduced. Sometimes they want you to learn by searching for the answers. In addition to completing the freeCodeCamp exercises and projects, I would strongly recommend reading documentation, Medium articles, and watching YouTube videos. Sometimes a text-based explanation on FCC is not enough for me, so I oftentimes look up video explanations to gain another point of view.
I like to think of freeCodeCamp as a roadmap. FCC does a great job at introducing topics, but I think you’ll need additional practice at nearly every concept to become proficient.
function titleCase(str) {
let strLower = str.toLowerCase();
let strLowerArr = strLower.split(" ");
let strLowerArrRet = [];
for (let i=0; i<strLowerArr.length; i++)
{
It looks like your code is a bit more complicated than you need. The second for loop is confusing and unnecessary. Try to concatenate the upper case letter with the rest of the original word and push to strLowerArrRet in the same for loop.
Right now your function returns undefined sometimes because this line strLowerArrRet[i] += strLowerArr[i][j];. You are incrementing j for each loop, which is soon exceeding the length of the words. But you don’t need this second for loop.
You could not create the second array and just substitute the elements of the first array while you are iterating over it so that it requires less memory