I realize that my approach isn’t elegant, and is clunky. I’m seperating each word into an array then just taking the capitalization of the first letter of each array. then finally combining them later on to be returned.
my question is for the line where i’m trying to upercase the first letter. It only outputs the first letter, and won’t loop through the whole array arr.
Also it looks like when I create teh array and add each letter if it isn’t a " " (space), the array has to be an empy string or else it will append to undefined how do I workaround if I don’t know how long the incoming string will be?
function titleCase(str) {
var arr=["","","","",""];
var cc=0;
str=str.toLowerCase();
//document.write(str[18]);
for(i=0;i<str.length; i++){
//if its a space increment the coutner fo the arr[aarray counter]
//otherwise itterage trhough str and push each letter into sepperate array.str[i].push()
// document.write(str[i])
arr[cc]+=str[i];
if(str[i]==" "){
cc++;
}
for(j=0;j<arr.length;j++){
document.write(arr[j][0].toUpperCase())
//arr[j][0]=arr[j][0].toUpperCase();
}
//document.write(arr);
//document.write(arr[cc])
//then we once its all split up we can capitalize each first letter after that combine them all togheter to make one sentence to return
}
//document.write(arr[0][0]+"<br>")
document.write(arr+"<br>")
return ;
}
titleCase("I'm a little tea pot");