#Not-working #Not-passing-test-cases #working-fine -in-online-compiler

Tell us what’s happening:
Describe your issue in detail here.

It is running fine and giving the same output in online compiler and here I am not able to pass test cases.
Your code so far

function titleCase(str) {
let my=str.split(" ");
let myStr="";
let result="";
for(var i=0;i<my.length;i++)

  myStr=my[i].charAt(0).toUpperCase()+myStr.slice(1,myStr.length)+" ";
// console.log(result);
return result;

titleCase("I'm a little tea pot");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36

Challenge: Title Case a Sentence

Link to the challenge:

You have an extra space at the end of your entire output string.

1 Like
      myStr=my[i].charAt(0).toUpperCase()+myStr.slice(1,myStr.length)+" "; 

I have tried this still it is not passing the test case

I don’t think you need to go thorugh all of that trouble to create an if else statement.

You basically just want to trim the extra spaces off the ends of your result string.

Lucky for you, there is a method in javascript that will do just that.

If you google,
how to trim space off of string javascript

then you will learn about that method and you can just add it at the end here
return result


Thankyou. Got to know about trimdEnd() .
but, still not passing test cases.

This is a spelling error.

sorry I used the correct one in my code. Spelling mistake here only.

Can I see your updated code?

Because when I run your code with the trim method it passes for me.

Hey Thanks.
I did some little mistake while updating the code. Now it is working fine. Thankyou

1 Like

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