# Capitalize the first character in the sentence

**URL:** <https://forum.freecodecamp.org/t/capitalize-the-first-character-in-the-sentence/178594>\
**Category:** General\
**Created:** [March 8, 2018, 2:56pm UTC](https://forum.freecodecamp.org/t/capitalize-the-first-character-in-the-sentence/178594 "2018-03-08T14:56:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![prabuselvan](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@prabuselvan](https://forum.freecodecamp.org/u/prabuselvan)\
**Post date:** [March 8, 2018, 2:56pm UTC](https://forum.freecodecamp.org/t/capitalize-the-first-character-in-the-sentence/178594/1 "2018-03-08T14:56:26Z")

</div>

**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**

````auto

    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:**
https://www.freecodecamp.org/challenges/title-case-a-sentence
````

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [March 8, 2018, 3:30pm UTC](https://forum.freecodecamp.org/t/capitalize-the-first-character-in-the-sentence/178594/2 "2018-03-08T15:30:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 6:44pm UTC](https://forum.freecodecamp.org/t/capitalize-the-first-character-in-the-sentence/178594/3 "2021-01-16T18:44:53Z")

</div>


