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

Concatenation javascript not working for me

I'm stuck on combining while making strings upperCase as in code below, I've tried several ways, i.e., +=, but can't seem to get this right, any help please?

var id = "23188xtr"; var lastName = "Smith";

var userName = "Smith".toUpperCase; + ".lastName".toUpperCase();

1 Answer

var id = "23188xtr"; var lastName = "Smith";

var userName = "Smith".toUpperCase; + ".lastName".toUpperCase();

you are close. the lastName variable in your concatination has a period and doesn't need it nor the quotation marks. Ths would be used if you were trying to get a classname of lastname and then would be in brackets. $(".lastname")

lastName.toUpperCase()

Also, with the "smith".toUpperCase you are leaving off the brackets which are necessary since its a function call

"Smith".toUpperCase()

as you are making a userName of SMITH + SMITH I think you are intending to ID+lastName

userName = id.toUpperCase() + lastName.toUpperCase();

Thanks Erik, So obvious when I viewed your reply, thanks that got me on the right track, the full answer I had to give was:

var id = "23188xtr"; var lastName = "#Smith";

userName = id.toUpperCase() + lastName.toUpperCase();

I had been trying to add the '#' in between the 2 var which set my code off wrong as well.