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 trialMatthew Munn
2,291 PointsJS: Storing and Tracking Information with Variables -code challenge solution?
I'm really struggling to figure out why this code isn't passing. Can anyone let me know why this string is incorrect?
JavaScript
var id = "23188xtr";
var lastName = "Smith";
id.toUpperCase();
lastName.toUpperCase();
var userName = id + "#" + lastName;
3 Answers
rydavim
18,814 Pointsvar id = "23188xtr";
var lastName = "Smith";
// This is not a persistent change unless you set the variable to it.
// ( This is destructive, so you probably don't want to do this. )
// Example: id = id.toUpperCase()
id.toUpperCase();
lastName.toUpperCase();
// You could also just put those method calls in the userName.
// ( This is probably a better idea. )
// Example: var userName = id.toUpperCase() + ...
var userName = id + "#" + lastName;
Dave McFarland
Treehouse TeacherHi Matthew Munn
The .toUpperCase()
and .toLowerCase()
methods don't actually CHANGE the original string -- they return (or give back) a version of that original string that is uppercased (or lowercased).
In other words you need to store the return value into another variable. For example:
var originalString = 'hello';
var newString = originalString.toUppercase();
Matthew Munn
2,291 PointsAwesome, thanks for the info and quick reply!