I’m trying to solve this problem with all the things I’ve learned so far, but my code is not working and the ways people are solving it is indeed very different.
My question here really is, why isn’t the following code doing the trick?
Just trying to understand the logic…
function titleCase(str) {
var newArray = str.toLowerCase().split(" ");
//Going through the array//
for (var i = 0; i < newArray.length; i++){
for (var j = 0; j < newArray[i].length; j++){
//if index is in index 0 (letter) of the word//
if (newArray[i][j] == newArray[i][0]){
//change letter to uppercase//
newArray[i][j].toUpperCase();
}
}
}
return newArray;
}
titleCase("i'm a little tea pot");