I am working on solving a basic coding challenge, I feel like my code SHOULD work. But this line is not reassigning correctly "str[i][0] = str[i].charAt(0).toUpperCase();"
I just don't know why this is working this way in Javascript, I think I've solved this same problem in Ruby without issue. Any tips or links on where to learn more about how this works in Javascript would be MUCH appreciated!
This is the challenge:
Return the provided string with the first letter of each word capitalized.
function titleCase(str) {
str = str.toLowerCase();
str = str.split(" ");
for (var i = 0; i < str.length; i++) {
str[i][0] = str[i].charAt(0).toUpperCase();
}
str = str.join(" ");
return str;
}
console.log(titleCase("I'm a little tea pot"));
Aucun commentaire:
Enregistrer un commentaire