Hey, can anyone tell me what am I doing wrong in Title Case a Sentence challenge?

Here’s my code it works just fine, but if we pass it a string “I’m a little tea pot”, it returns “I’M A Little Tea Pot”, not “I’m A Little Tea Pot”.
I’d appreciate if anyone could help me :slight_smile:

function titleCase(str) {
    let lowerStr = str.toLowerCase();
    let newStr = lowerStr.replace(/\b\w/g, c => c.toUpperCase());
    return newStr;
}

I think the \b token does not do what you want it to do. It looks for chars that do not match \w, which would include the apostrophe.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.