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 trialAngela Bortone
7,405 PointsI'm having difficulty with this code challenge.
When I try to use concatenation to alter the variable username to complete the second objective the first part of the challenge no longer passes. What's up?
The final value of username should be '23188XTR#SMITH'
var id = "23188xtr";
var lastName = "Smith";
var userName = id.toUpperCase();
username = username + "#";
username += lastName.toUpperCase();
1 Answer
Stephen Bone
12,359 PointsHi Angela
You're almost there.
After the initial declaration and assignment of userName you are then just missing out the capital N in userName.
So your code should be as below:
var id = "23188xtr";
var lastName = "Smith";
var userName = id.toUpperCase();
userName = userName + "#";
userName += lastName.toUpperCase();
As the code below was my initial and poor attempt to answer the question I'll leave it here just as an alternative way to do it.
For example:
var userName = id.toUpperCase() + "#" + lastName.toUpperCase();
Hope it helps!
Stephen
John Magee
Courses Plus Student 9,058 PointsJohn Magee
Courses Plus Student 9,058 PointsExcept there is nothing wrong with how she wrote the code...getting the solution correction should be the goal - the check code needs to be more forgiving
Stephen Bone
12,359 PointsStephen Bone
12,359 PointsHi John
Yeah I can't disagree with you. I was actually just continuing to play with her code to see if I could get it to pass.
I wondered if it didn't like the attempt to concatenate using the += but even taking that out and re-jigging it a few different ways I can't get it pass except using with the way I demonstrated.
Stephen
Stephen Bone
12,359 PointsStephen Bone
12,359 PointsScratch that the code does work I just realised that the variable isn't capitalised properly.
Using username rather than userName.
I will update my original post to reflect this. Apologies as I should have spent longer looking at the actual code rather than working out how I would complete it.
Angela Bortone
7,405 PointsAngela Bortone
7,405 PointsI capitalized the rogue letter and it worked! Is JavaScript particular about keeping the lower/upper/camel/case consistent - I thought in an earlier video Dave said that it wasn't so important other than for readability.
John Magee
Courses Plus Student 9,058 PointsJohn Magee
Courses Plus Student 9,058 PointsSharon
Javascript is VERY case sensitive (most programming languages are actually) and it's important to remember the case sensitivity especially when you get into more 'complex' things that you really will want to use (for instance getElementById).