I can probably solve this another way but I would love to understand what I’m doing wrong here. I really appreciate if someone could explain it to me. Thanks in advance!
Your code so far
function titleCase(str) {
let newArr = [];
const regex = /+w/;
str.split(" ").forEach(word => {
for (let i = 0; i < word.length; i++) {
let newWord = "";
if (i == 0 && word[i].match(regex)) {
newWord + word[i].toUpperCase();
} else {
newWord + word[i].toLowerCase();
}
newArr.push(newWord);
}
});
return newArr.join(" ");
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0
.
Challenge: Title Case a Sentence
Link to the challenge: