Output not getting verified

Tell us what’s happening:

My code seems to get the right output for individual test cases. However, when I run the program, the test cases fail. Could someone tell me what I am missing here?

  **Your code so far**

function titleCase(str) {
let arrStr = str.split(' ');

let sentenceString = '';
arrStr.forEach(element => {
  let arr = element.split('')
  let wordStr = '';
  arr.forEach((ele, index) => {
    if(index == 0){
      ele = ele.toUpperCase();
    }
    else{
      ele = ele.toLowerCase();
    }
    wordStr = wordStr.concat(ele,'');
  })
  sentenceString=sentenceString.concat(wordStr,' ');
});
str = sentenceString;
console.log(str);
return str;
}

titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");

  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36

Challenge: Title Case a Sentence

Link to the challenge:

I would write here instead something like

console.log('"' + str + '"')

just to be sure

If you do that change, what do you in your output?

This is what I get :

"I'm A Little Tea Pot "
"I'm A Little Tea Pot "
"I'm A Little Tea Pot "
"Short And Stout "
"Here Is My Handle Here Is My Spout "
"I'm A Little Tea Pot "

The outputs should be

"I'm A Little Tea Pot"
"Short And Stout"
"Hese Is My Handle Here Is My Spout"

do you see the difference?

1 Like

Thank you so much! Got it. I called the .trim() at the end and it was a success! Thanks.

1 Like

awesome! Good Job! :grinning_face_with_smiling_eyes:

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