Hi! This is my code so far. I´ve passed all the test, except the one with the string “I’m a little tea pot”, My code returns “I’M A Little Tea Pot” instead of “I’m A Little Tea Pot” and I don´t know how to fix it. Thank you in advanced!
Your code so far
function titleCase(str) {
let regex = /\w+\D/ig;
let words = str.match(regex);
let newStr = "";
for (let word in words){
newStr += words[word][0].toUpperCase() + words[word].slice(1).toLowerCase();
}
return newStr;
}
console.log(titleCase("I'm a little tea pot"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Title Case a Sentence
Ohh okay, now I get way it does not work. The problem is that it separetes the " I’m " after the apostrophe instead of before (‘I'’, 'm ').
I’m not sure how to fix it, since if I change the regex for /\D\w+/ig it completely ignores the “I”