Https://www.freecodecamp.org/challenges/title-case-a-sentence

Https://www.freecodecamp.org/challenges/title-case-a-sentence
0

#1

Tell us what’s happening:
I’m stuck on this exercise. My code doesn’t work. I get a Type Error, and the statement that the contents of my for loop isn’t a function.
Can someone tell me what’s wrong here?

Your code so far

function titleCase(str) {
  var textSplit = str.split();
  var textArray = [];
  for (var i = 0; i < textSplit.length; i++) {
    textArray[i] = textSplit[i].toLowerCase().replaceAt(0, textSplit[i].charAt(0).toUpperCase()); 
  }
  

  return textArray.join(' ');
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36.

Link to the challenge:


#2

Method replaceAt doesn’t exist in the string prototype.

EDIT:

  • You have used split wrong, you need to pass in an argument with a value of where to split.
  • Try to use substr method to solve this problem.

#3

You need to call the split function with a delimiter, similar to the way you used the join function in your return statement.


#4

Thanks! Now I see the problem.