Title Case a Sentence need help

I’m struggling with this one. This is what i have so far.

function titleCase(str) {
  var newStr = str.split(" ");
  var Arr = [];
  for(let i =0; i < newStr.length; i++){

     Arr[i] = newStr[i].charAt(0).toUpperCase();     
    }return Arr.join(' ');

console.log(titleCase("I'm a little tea pot"));


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


You’re actually closer than you think.

As you have probably figured out you have so far captured the first letter of each word and capitalized it. That’s half the task so half way there. Plus you’ve conquered reuniting array elements back into a single string. There’s just a middle step missing.

You cannot mutate a string in place so you’ll need to think of a way to get the remaining letters merged back into a string with their corresponding (now capitalized) first letter.

I don’t have a link to that challenge. Were there any string methods suggested or hinted at in the instructions?

I cant seem to figure out how to attach the rest of the string. This is the solution i keep seeing, but i really don’t understand it.

String.prototype.replaceAt = function(index, character) {
    return this.substr(0, index) + character + this.substr(index+character.length);

function titleCase(str) {
    var newTitle = str.split(' ');
    var updatedTitle = [];
    for (var st in newTitle) {
        updatedTitle[st] = newTitle[st].toLowerCase().replaceAt(0, newTitle[st].charAt(0).toUpperCase());
    return updatedTitle.join(' ');

Link to challenge

I figured it out finally!!!