Title Case Challenge: Code Review

Tell us what’s happening:
Can anyone please help me figure out why the below LOCs are not accepted?

Just to be sure, the outcomes are, I think, what is expected.

  **Your code so far**

function titleCase(str) {
  const arrOfStrings = str.split(" ");
  let casingWords;
  let cased = "";

  for (let i of arrOfStrings) {
    // uppercase the first index and lowercase the rest for each words
    casingWords = i[0].toUpperCase() + i.slice(1).toLowerCase();

    cased += casingWords + " ";

  return cased;

 console.log(titleCase("I'm a little tea pot"));
//I'm A Little Tea Pot

console.log(titleCase("sHoRt AnD sToUt"));
//Short And Stout

console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
//Here Is My Handle Here Is My Spout

Please find the repo here: Github Repo

Challenge: Title Case a Sentence

Link to the challenge:

Hi @Dtech-Dbug !

This is a common problem most people run into with this challenge.

Take a close look at this line here

Right now you are adding the casingWords plus a space to the case variable.

The problem is, you have created an extra space at the end of your string.

You need to google this phrase
how to remove space at the end of string in javascript

The first result will give you the exact string method you should use for your return statement here

Then the test will pass


ahhhh @jwilkins.oboe perfect!!

Thanks for pointing this out in such a comprehensible way :slight_smile:

I guess I will use some trimEnd() method to remove the trailing space :slight_smile:

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