Capital letter problem in "Title Case a Sentence"

Tell us what’s happening:
Why does it not work??

Your code so far

function titleCase(str) {
let sentence = str.toLowerCase().split(" ");
for (let i = 0; i < sentence.length; i++){
  sentence[i][0] = sentence[i][0].toUpperCase();
return sentence.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/84.0.4147.89 Safari/537.36.

Challenge: Title Case a Sentence

Link to the challenge:

Strings are immutable.

There was a challenge on string immutability here:

1 Like

any suggestions?

change the whole string instead of a single character inside it, you can use slice to get the rest of the string for example

or, array are mutable instead

why does this not work??

join returns a new string

1 Like