Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Anybody help with RegEx?

Hi all

Can anybody tell me why this isn't working. I've been staring at it for hours.

function LetterCapitalize(str) {
    return str.replace(/\b[a-z]/gi, function(x) {
        return x.toUpperCase();
    })
}
letterCapitalize('hello world');

It's supposed to target the first letter of each word then capitalize them. Regex editors online say it's correct. Help

Paul

1 Answer

Your regex is great! When I tried to run your code, though, I noticed your function is uppercased in the declaration, but lowercased when you call it, so that might be the problem you're having! You'll also need to either modify the function or store the result in a variable when you call it, right now it's returning the capitalized string, but you need to capture it somewhere in order to use it. I just popped the call inside a console.log() and got Hello World :-)

Oh my god thanks so much

Of course!