Title Case a Sentence exercise issue

Tell us what’s happening:

Hi guys,
On the Title Case a Sentence exercise, my code pass all the tests and even I made others more specifically regarding regexp such as symbols and numbers and still the exercise doesn’t let me keep going. Is anything wrong with my code or is a problem with the exercise itself?

Thank you so much.
Regards,
Javier

Your code so far

function titleCase(str) {
  var word = str.replace(/[^A-Z^a-z^şŞıİçÇöÖüÜĞğ^' ]+/i, '');
  word = word.split("");
  var firstChar = word.shift().toUpperCase();
  word = word.join("").toLowerCase();
  word = firstChar + word;
  return word;
}

titleCase("sHoRt AnD sToUt");
titleCase("7hello");
titleCase("&hello");

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/65.0.3325.162 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/title-case-a-sentence

I’m not sure what you’re looking at, but your code doesn’t pass any of the tests bar the first (which only checks the returned value is a string):

52

You’re only uppercasing the first letter and you’re not lowercasing the rest of the letters. Plus you’re removing anything that isn’t in a list of specific characters you’ve chosen, which the task is not asking you to do.

function titleCase(str) {

This isn’t necessary at all, you aren’t being asked to remove any characters:

  var word = str.replace(/[^A-Z^a-z^şŞıİçÇöÖüÜĞğ^' ]+/i, '');

This then gives you an array of all the characters:

  word = word.split("");

Which you then only take the very first character from:

  var firstChar = word.shift().toUpperCase();

Then you join that array back up:

  word = word.join("").toLowerCase();

And add the uppercased first letter back on:

  word = firstChar + word;
  return word;
}

titleCase("sHoRt AnD sToUt"); should return Short And Stout, but your code returns SHoRt AnD sToUt

titleCase("7hello"); should return 7hello - uppercasing “7” will leave it as “7” - but your code returns Hello.

titleCase("&hello"); should return &hello - uppercasing “&” will leave it as “&” - but your code returns Hello


Hint:

Summary

You can to split the string on spaces so that you have a list of words, then for each word you want to lowercase the word, do the jiggery-pokery to uppercase the first character, then join the list of words back together with a space inbetween.

What I meant and the weird part of everything that my code returned everything all right was on the result (now I removed the replace statement):

.

And I think you didn’t realize but I used the lower case method:
word = word.join("").toLowerCase();

If you see, below the " Ask for help on the forum" button you see that m function returns “Short and stout”, and yet do not let me pass.
And same happen when I tried I’m a little pot, hello and etc… :frowning:

Apologies, I missed the lower casing.

This is not what it should return, hence the test fails. You are being asked to title case the sentence, not capitalize just the first letter in the sentence - “Short And Stout” rather than “Short and stout”. Look at what the failing tests say, they are telling you what the return value should look like - what you are returning does not match what they are asking for.