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!
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
Elena Paraschiv9,938 Points
Using String Methods challange_code
Complete the assignment to the userName variable by adding a # symbol followed by an all uppercase version of the lastName variable. In other words, using string concatenation so that the final value of userName is "23188XTR#SMITH". Did someone manage to fix this?
var id = "23188xtr"; var lastName = "Smith"; var userName = id.toUpperCase(); userName = lastName.toUpperCase(); username = "id" + "#" + "lastName";
There are a number of ways to solve this challenge, but the most important concept to take away is that when doing operations with variables, such as concatenation with strings, you do not put those variable names inside of quotes. You just put the variable name itself.
Also, you have to think about what the end result is. The string should be upper case id, a # sign, and then upper case last name. With the way you have it right now, it starts out as upper case id. Then, it is overwritten and becomes only upper cast last name. Then, it is overwritten a 2nd time and becomes a string that says "id#lastName". It needs to have the values contained within
lastName. In order to do that, you just use the variable name as I mentioned above.
The simplest method to solve this is to just add the "#" after putting id to upper case and then add last name to upper case.
var id = "23188xtr"; var lastName = "Smith"; //put the upper case version of id plus a # plus last name to upper case var userName = id.toUpperCase() + "#" + lastName.toUpperCase();