Title Case a Sentence - new coder!

Title Case a Sentence - new coder!
0

#1

Hello,

I have wrote this code and not sure why its not working. I am probably totally off but here is my code that I have attempted…any input appreciated…

function titleCase(str) {
var allensArray = str.toLowerCase().split(" ");

for (i = 0; i < allensArray.length; i++){
allensArray[i].charAt(0).toUpperCase();

}

var newArray = allensArray.join(" ");
return newArray;
}

titleCase(“I’m a little tea pot”);


#2

The line below for loop is not getting assigned to anything.


#3

so i did this,

and still not working…doh

function titleCase(str) {
var allensArray = str.toLowerCase().split(" ");

for (i = 0; i < allensArray.length; i++){
var newArray = allensArray[i].charAt(0).toUpperCase();
var latestArray = newArray.join(" ");
}

return latestArray;
}

titleCase(“sHoRt AnD sToUT”);


#4

Only line below for loop needs changing. That piece has to be assigned to allensArray[i] and concatenated with the remainder of the word.
You might wanna use this to get the remaining piece.
https://www.w3schools.com/jsref/jsref_substr.asp


#5

Figured it out! thanks @Quickz