Title Case a Sentence-Code works but I cant't pass the test

Title Case a Sentence-Code works but I cant't pass the test
0

#1

My code for this challenge works fine. However, I can’t pass the challenge when I run tests. Here is my code:

function titleCase(str) {
str=str.toLowerCase();
var array=str.split(’ ');
for(var i=0;i<array.length;++i){
array[i]=array[i].replace(array[i].charAt(0),array[i].charAt(0).toUpperCase());

}
str="";
for(var j=0;j<array.length;++j){
str=str+array[j]+" ";
}
return str;
}

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


#2

Shooting in the dark here, but does it want a semicolon after: for(var j=0;j<array.length;++j);


#3

Your output string is not matching the tests because your second for loop adds a space after the last word.


#4

Oh yes, I didn’t notice that. Thanks, I fixed it.


#5

Ah no, in case of for loops you need curly brackets like {}. There is no need for semicolons.