# Hello, what's wrong with my code?

**URL:** <https://forum.freecodecamp.org/t/hello-whats-wrong-with-my-code/147558>\
**Category:** General\
**Created:** [September 12, 2017, 3:40pm UTC](https://forum.freecodecamp.org/t/hello-whats-wrong-with-my-code/147558 "2017-09-12T15:40:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joelatiam](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@joelatiam](https://forum.freecodecamp.org/u/joelatiam)\
**Post date:** [September 12, 2017, 3:40pm UTC](https://forum.freecodecamp.org/t/hello-whats-wrong-with-my-code/147558/1 "2017-09-12T15:40:23Z")

</div>

[https://www.freecodecamp.org/challenges/title-case-a-sentence](https://www.freecodecamp.org/challenges/title-case-a-sentence)

function titleCase(str) {  
var myArray = str.split(" ");  
var myStr;  
var convertedString = “”;

```
for (i=0; i<myArray.length; i++){
  //select each word
  myStr = myArray[i];
  var newArray = myStr.split("");
  //Convert the first letter of the word to uppercase
  newArray[0] = newArray[0].toUpperCase();
  //convert the remaining letters to lowercase
  if(newArray.length>1){
    for(y=1; y < newArray.length; y++){
      newArray[y] = newArray[y].toLowerCase();
    }
  }
    
  var newStr = newArray.join("");
  convertedString = convertedString.concat(newStr," ");
  
  
}

```

str = convertedString;  
return str;  
}

titleCase(“HERE IS MY HANDLE HERE IS MY SPOUT”);

 ![freecode](https://global.discourse-cdn.com/freecodecamp/original/3X/b/c/bc9f0eefd861c59b420017d11b305e588fc96874.PNG)

---

<div class="post-metadata">

**Author:** ![sonimadhuri](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sonimadhuri/32/66596_2.png) [@sonimadhuri](https://forum.freecodecamp.org/u/sonimadhuri)\
**Post date:** [September 12, 2017, 3:54pm UTC](https://forum.freecodecamp.org/t/hello-whats-wrong-with-my-code/147558/2 "2017-09-12T15:54:57Z")

</div>

There is an extra space at the end of the returned string ![Capture](https://global.discourse-cdn.com/freecodecamp/original/3X/e/e/ee8d5e227bc64af41b0e7795d423fb3db9965de7.PNG)  
Notice the space after `Spout` .you could use trim() function to remove the extra space

---

<div class="post-metadata">

**Author:** ![joelatiam](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@joelatiam](https://forum.freecodecamp.org/u/joelatiam)\
**Post date:** [September 12, 2017, 4:08pm UTC](https://forum.freecodecamp.org/t/hello-whats-wrong-with-my-code/147558/3 "2017-09-12T16:08:47Z")

</div>

Thank you, now it works

---

<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:39pm UTC](https://forum.freecodecamp.org/t/hello-whats-wrong-with-my-code/147558/4 "2021-01-17T20:39:56Z")

</div>

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


