Title Case a Sentence(what is the mistake here ?)

Tell us what’s happening:

Your code so far

function titleCase(str) {
  str = str.split(' ');

  for (i = 0; i < str.length; i++) {
    str[i] = str[i].split('');

    str[i][0] = str[i][0].toUpperCase();
    for (i = 1; i < str.length; i++) {
    str[i] = str[i].toLowerCase();
  str[i] = str[i].join('');

  return str.join(' ');

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 OPR/50.0.2762.58.

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a 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.


1 Like

At this point in your code, str[i] is an array and not a string, so you can not use the toLowerCase function on it.