# Title Case Sentence challenge

**URL:** <https://forum.freecodecamp.org/t/title-case-sentence-challenge/106599>\
**Category:** General\
**Created:** [April 16, 2017, 9:39pm UTC](https://forum.freecodecamp.org/t/title-case-sentence-challenge/106599 "2017-04-16T21:39:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bazita](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bazita/32/46710_2.png) [@bazita](https://forum.freecodecamp.org/u/bazita)\
**Post date:** [April 16, 2017, 9:39pm UTC](https://forum.freecodecamp.org/t/title-case-sentence-challenge/106599/1 "2017-04-16T21:39:23Z")

</div>

Please, I need help , take look to my code tell me what’s wrong.

```auto
function capitalFirstLetter(a)	{
var i=0; 
var string;
var result="";
var newArray=[];
var finalSentence;
  	                  string = a.toLowerCase();  
                           var myArray =string.split();
 			   var arrayLength= myArray.lenght;

  for ( i<arrayLength; i++; ) {	
result=myArray[i].charAt(i).toUpperCase() + myArray[i].slice(1);
 finalSentence =join().push(result);
     	    	 }

     return finalSentence;
}

```

---

<div class="post-metadata">

**Author:** ![pompan129](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pompan129/32/73280_2.png) [@pompan129](https://forum.freecodecamp.org/u/pompan129)\
**Post date:** [April 16, 2017, 9:48pm UTC](https://forum.freecodecamp.org/t/title-case-sentence-challenge/106599/2 "2017-04-16T21:48:58Z")

</div>

There are a few problems here. To start `string` is a reserved word. Use another variable name. 2nd .split() requires a separator. (ie. .split(" ")). Also. `myArray.lenght` length is spelled wrong. Start with that and see how much that helps to start.

---

<div class="post-metadata">

**Author:** ![BenGitter](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bengitter/32/12192_2.png) [@BenGitter](https://forum.freecodecamp.org/u/BenGitter)\
**Post date:** [April 16, 2017, 9:55pm UTC](https://forum.freecodecamp.org/t/title-case-sentence-challenge/106599/3 "2017-04-16T21:55:29Z")

</div>

Besides the things @pompan129 pointed out, you should also have a look at the `for` loop.

I would suggest to place the `var i = 0` inside the for loop: `for(var i = 0; i < arrayLength; i++)`. You can declare the variable outside of the for loop, but then you should use: `for(; i < arrayLength; i++)`, note the semi-colon directly after the first parenthesis. Also, there should be no semi-colon after `i++`.

[https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/for](https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/for)

---

<div class="post-metadata">

**Author:** ![rubendmatos1985](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@rubendmatos1985](https://forum.freecodecamp.org/u/rubendmatos1985)\
**Post date:** [June 26, 2017, 5:03am UTC](https://forum.freecodecamp.org/t/title-case-sentence-challenge/106599/4 "2017-06-26T05:03:28Z")

</div>

Hello friends

i completed the challenge but i i dont know why he page dont let me go through.

here i let my code. I was 6 hours trying to find the code, i had to do a lot of research in internet, but i did it, sadly the web site dont let me go forward. i need some help. I made the code in Sublime Text 3

function titleCase (str) {  
var minusculas = str.toLowerCase(); /_Conversion de todas las palabras a minusculas_/  
var palabras = minusculas.split(" "); /\* metodo split para separar las palabras de la cadena\*/  
var oracion = “”

palabras.forEach(function(word, index, array){ /\* bucle for Each para iterar sobre las palabras\*/

```
var mayusculas = word.replace(word[0], word[0].toUpperCase()); /*remplazar con el metodo replace las letras 0 de cada palabra por la letra en mayusculas */
 
oracion = oracion + " " + mayusculas; /*guardo en una variable cada operacion del bucle*/

```

}); console.log(oracion)

}

titleCase(“otro ejercicio mas que hago solo”); /\* Llamando a la funcion con los parametros\*/

---

<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:52pm UTC](https://forum.freecodecamp.org/t/title-case-sentence-challenge/106599/5 "2021-01-17T20:52:45Z")

</div>

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


