Title Case Algorithm Challenge

Hey fellow Campers. I’m working on the Title Case Algorithm Challenge. Well, more accurately, I peeked at the solution out of frustration, and now I’m just trying to understand why mine didn’t work.

function titleCase(str) {
  var words = str.toLowerCase().split(" ");
  for(var i=0; i<words.length; i++){
    words.join(" "); 
  return words;

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

Any feedback on why this doesn’t pass muster?

This does nothing. .toUpperCase returns a new string representing the calling string converted to upper case. It does not modify the original string.

You can do this:

    var firstLetterOfWord = words[i][0].toUpperCase();
    console.log(firstLetterOfWord); // displays the upper case version of the 1st letter in each word

Then you can use firstLetterOfWord and combine it with the remainder of the word and assign it back to words[i] before joining the words back together.

1 Like

Thanks for the reply.

So just so I’m clear on this, the “calling string” would be whatever comes before .toUpperCase()?
E.g. - callingString.toUpperCase()?

So, I have to assign the function call to a variable in order to make it so I can work with it? Am I understanding you correctly?

Yes, you are correct.

1 Like