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
Kennen Pflughoeft2,749 Points
Getting at message that Task 1 is not passing, but if I concatenate this sting, shouldn't Task 1 not pass here?
I'm not sure how both task 1 and task 2 should pass once I concatenate this string, this makes it hard to trust this error message.
var id = "23188xtr"; var lastName = "Smith"; var userName = id.toUpperCase(); var userName += "#"; var userName += lastName.toUpperCase();
Jason AndersTreehouse Moderator 145,855 Points
Hi Kennen, The reason you are getting the error, is because your are using 'var' on each instance of the concatenation. The challenge complier just sees this error and returns that the first task is no longer passing, because the value for user name is now "lastName.toUpperCase(). Every time you use var, you are basically wiping whatever was in there before and putting in a new value.
The correct way to concatenate this string (and being DRY) is
userName = userName + "#" + lastName.toUpperCase(); //do not use var in the front.
Hope that makes sense. Jason :)