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 trialShashaank Srinivasan
2,440 PointsI've inserted the '#' symbol in quotations, what am I missing in the code?
Any help is greatly appreciated.
var id = "23188xtr";
var lastName = "Smith";
var userName = "id"+"#"+"lastName" .toUpperCase();
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
5 Answers
Navid Mirzaie Milani
6,274 Points@Shashaank Srinivasan what do you want to achieve? because when i just type the code you write in the example i get :
var userName = "id"+"#"+"lastName".toUpperCase();
result is: id#LASTNAME. So whats going wrong at your?
Rich Donnellan
Treehouse Moderator 27,696 PointsYou're literally outputting "id"
and "lastName"
. Variables will not work with quotes (single or double); remove them from id
and lastName
.
Charles Lee
17,825 PointsThe problem as mentioned by Rich is the incorrect use of variables but also missing the task.
The task is asking to add a #
symbol and an uppercased version of the last name to the uppercase of the id.
// Your solution:
var userName = "id"+"#"+"lastName" .toUpperCase();
Here you aren't using the variables id
and lastName
but using the strings "id" and "lastName".
You want to use those as variables.
var userName = id + '#' + lastName.toUpperCase();
We have something closer to the solution, but now we're getting only the lastName variable to be in uppercase. To get the whole string to be uppercase we can either uppercase the individual parts or to uppercase the overall string as so:
// version 1
var userName = (id + '#' + lastName).toUpperCase();
// OR
// version 2
var userName = id.toUpperCase() + '#' + lastName.toUpperCase();
Since we want to keep things DRY, we probably want to use the first version.
Best,
Charles C. Lee :D
Navid Mirzaie Milani
6,274 Pointsaaah damn .. i didn't even recognise the mistake ... and those were variables my bad indeed and Charles Lee is right :).
Rich Donnellan
Treehouse Moderator 27,696 PointsIt's also worth mentioning that this question has been asked many, many times. Peruse the JavaScript related forum for any potential clues before posting your own.
Cheers!
Shashaank Srinivasan
2,440 PointsThanks so much, that worked perfectly