Hello, what's wrong with my code?

Hello, what's wrong with my code?
0

#1

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”);


#2

There is an extra space at the end of the returned string Capture
Notice the space after Spout .you could use trim() function to remove the extra space


#3

Thank you, now it works