Title_Case_a_Sentence

Tell us what’s happening:
Hi All,
I try to understand where i made mistakes. Even though there are also solutions provided by freeCodeCamp but i do not understand them as well. I tried to use logic but it is not working :frowning:

Your code so far


function titleCase(str) {
let strArray = str.split(' ');
let words = [];

for(let i = 0; i < strArray.length; i++){
words[i] = strArray[i].toLowerCase();
words[i] = words[i].replace(0, words[i].charAt(0).toUpperCase());
}
return words.join(" ");
}

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

Challenge: Title Case a Sentence

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence

Welcome to the forum, @Mina4!

What represents 0 inside replace? If you’re trying to replace first letter of words[i],you can use the charAt(0) on the words[i] as you did in the second half of replace method.

One more thing,when you are stuck at some point,try to use console.log() to see what is current output and what you can fix…

Hope this makes sense,and that you can implement this into your solution!

1 Like

Thank you for your help.