What to do - Capitalize the first letter of the words in a sentence.
So, I solved it and was wondering is there any way to do it without making it an array with .split()
.
What I tried without turning it into a array -
The logic - First, turn everything into lowercase. Then scan the sentence with a for loop, if you find a space, capitalize the next character.
function titleCase(str) {
str = str.toLowerCase();
for(i=0;i<str.length;i++) {
if(str[i]===" ") {
str = str.charAt[i+1].toUpperCase();
return str;
}
}
}
titleCase("I'm a little tea pot", "");
That code doesn't even run.