Basic Algorithm's Title a case's solution isn't work

Tell us what’s happening:
Describe your issue in detail here.
all outcomes are okay but the test’s results always fail. why that’s happened?

  **Your code so far**

function titleCase(str) {
let result = '';
let convert = str.split(" ")
for(let value of convert){
  let con = value[0].toUpperCase() + value.slice(1).toLowerCase();
  result = result + " " + con
}
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/92.0.4515.131 Safari/537.36

Challenge: Title Case a Sentence

Link to the challenge:

Hi @souemon16 !

Look very carefully at this line here

The first time it is run it adds an extra space before the word I'm

That is your issue.

Thank you @jwilkins.oboe
now I got the point.
I solve the problem just using trim() method. I used trim() on the result and now the code is working.

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