Title Case a Sentence 4

Tell us what’s happening:

Hi, campers.

Can someone explain to me why this code is not working?

Your code so far

function titleCase(str) {

let newStr = str.toLowerCase().split(" ");

for(let i = 0; i < newStr.length; i++) {
  let firstLetter = newStr[i].charAt(0);
  newStr[i].replace(firstLetter, function (letter) {
return newStr.join(" ");

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36.

Link to the challenge:

Pretty sure it because of how replace works.

The replace() method returns a new string

The original string is left unchanged.

If you make a new array and push the result of the replace into it and return that you should pass.

Thanks lasjorg. Now it’s clear to me