why my code is wrong?
Basic Algorithm Scripting: Title Case a Sentence it doesn’t accept it?!
Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
For the purpose of this exercise, you should also capitalize connecting words like “the” and “of”.
function titleCase(str) {
let str2=str.split(' ');
let capsStr="";
for(let i=0;i<str2.length;i++){
let correctWord = "";
let letter="";
for(let j =0 ; j<str2[i].length;j++){
if(j==0){
letter = str2[i].charAt(0).toUpperCase();
}else{
letter = str2[i].charAt(j).toLowerCase();
}
correctWord +=letter;
}
capsStr +=correctWord+" ";
}
return capsStr;
}
titleCase("I'm a little tea pot");