# Algorithms- Title Case A Sentence

**URL:** <https://forum.freecodecamp.org/t/algorithms-title-case-a-sentence/137560>\
**Category:** General\
**Created:** [July 21, 2017, 11:02pm UTC](https://forum.freecodecamp.org/t/algorithms-title-case-a-sentence/137560 "2017-07-21T23:02:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfasf](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alfasf/32/66712_2.png) [@alfasf](https://forum.freecodecamp.org/u/alfasf)\
**Post date:** [July 21, 2017, 11:02pm UTC](https://forum.freecodecamp.org/t/algorithms-title-case-a-sentence/137560/1 "2017-07-21T23:02:17Z")

</div>

Hello another post here. I’m working on the Title Case a Sentence exercise. I was able to came up to this solution using a for loop. First I created a variable to lowecase the string, then the result of this variable will be store in an another variable separating/splitting the string into array of words. Once I got my array of words, I made the for loop using the latest variable to iterate each array. I think this has worked so far but when I pass the string into the function, the result duplicates the first letter of each array both lower case and upper case. Did I miss something in here just to get the result of the upper case?

function titleCase(str){  
var lowerCase = str.toLowerCase();  
eachWord = lowerCase.split(" ");  
for (i = 0; i \< eachWord.length; i++){  
eachWord[i] = eachWord[i].charAt(0).toUpperCase()+eachWord[i].split(1)  
}

```
return eachWord.join(" ");

```

}

titleCase (“JavaScript is hard.”);

---

<div class="post-metadata">

**Author:** ![ccwoolfolk](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ccwoolfolk/32/127013_2.png) [@ccwoolfolk](https://forum.freecodecamp.org/u/ccwoolfolk)\
**Post date:** [July 22, 2017, 1:28am UTC](https://forum.freecodecamp.org/t/algorithms-title-case-a-sentence/137560/2 "2017-07-22T01:28:55Z")

</div>

I’m the final line of your loop, I think you want to choose a different string method for `eachWord[i].split(1)`. Judging by the parameter you provided to `split`, I would go so far as to guess that you actually meant to type the right method and just made a typo. Chime back in if you need a more specific hint or are stuck. 😀

---

<div class="post-metadata">

**Author:** ![alfasf](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alfasf/32/66712_2.png) [@alfasf](https://forum.freecodecamp.org/u/alfasf)\
**Post date:** [July 22, 2017, 1:46am UTC](https://forum.freecodecamp.org/t/algorithms-title-case-a-sentence/137560/3 "2017-07-22T01:46:04Z")

</div>

Thank you so much for helping debug. I really mix up slice and split. I understand the concept of each but for some reason I mix these two.  
I don’t know but javascript is getting hard to grasp for me. I should keep practicing and practicing.  
Again thanks a lot for the observation!

---

<div class="post-metadata">

**Author:** ![ccwoolfolk](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ccwoolfolk/32/127013_2.png) [@ccwoolfolk](https://forum.freecodecamp.org/u/ccwoolfolk)\
**Post date:** [July 22, 2017, 1:50am UTC](https://forum.freecodecamp.org/t/algorithms-title-case-a-sentence/137560/4 "2017-07-22T01:50:12Z")

</div>

No worries. The other day I spent at least an hour debugging a simple typo (logical OR operator vs bitwise OR … look so similar when you aren’t paying attention!), so these things happen!

---

<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 17, 2021, 8:47pm UTC](https://forum.freecodecamp.org/t/algorithms-title-case-a-sentence/137560/5 "2021-01-17T20:47:35Z")

</div>

Closed on January 17, 2021, 8:47pm UTC


