Title Case a Sentence Failing tests

Hello, please i need help.
I dont know what is wrong with my function, it outputs the same thing and i cant pass the challenge.
Thank you in Advance
Here is my code:

function titleCase(str) {
  let arr = str.split(" ");
  let newStr = '';
  for(let i = 0; i<arr.length; i++){
    let res = arr[i].charAt(0).toUpperCase() + arr[i].slice(1).toLowerCase();
    newStr = newStr.concat(res, ' ')
  }
  return newStr;
}

what’s the challenge link?

hey @nadahosni96,

This is probably failing due to extra space at the end try return newStr.trim() to trim space off the ends.

1 Like

Yep extra space at the end.

Screen Shot 2020-11-10 at 10.13.04 PM

@BatmanFreeCodeCamper @biscuitmanz
THANK YOU A LOT FOR YOUR HELP :smile:

2 Likes