Capitalize the first character in the sentence

Tell us what’s happening:
My code is working fine. When i submit in freecode camp i am unable to submit it. I am getting below error.

titleCase(“I’m a little tea pot”) should return “I’m A Little Tea Pot”.
titleCase(“sHoRt AnD sToUt”) should return “Short And Stout”.
titleCase(“HERE IS MY HANDLE HERE IS MY SPOUT”) should return “Here Is My Handle Here Is My Spout”

Your code so far

    var newstr=str.split(" ");
    var temp=" ";
    for (var i=0; i<newstr.length; i++) {
     temp=temp +" "+ newstr[i].charAt(0).toUpperCase() + newstr[i].slice(1).toLowerCase();

    return temp;


console.log(titleCase("sHoRt AnD sToUt"));```
**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36```.

**Link to the challenge:**

It looks like you probably have leading spaces at the start of your string.