Replace only works for strings

So I wrote:

function titleCase(str) {
  var words = str.split(' ');
  words = words.map(word => word.toLowerCase())
  for (var i=0; i<words.length; i++) {
  }
  console.log(words)
  return str;
}

Hint 1 states:

- You should start by splitting the string into an array of words.
- Split the sentence.

Which I did with the first line.

Then Hint 2 says:

- You should make the word lowercase before making the first letter uppercase.
- Use replace method on each word to capitalize the first letter of each word.

I did the first bullet point with map but replace seems to only work for strings not arrays.

Hello!

Yes, replace does indeed only work with strings, not arrays. The hint tells you:

Use replace method on each word to capitalize the first letter of each word.

Not the entire array (if you attempted that, of course :stuck_out_tongue:):

words = words.map(word => /* use replace here */ word.toLowerCase())

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.