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 trial

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Using String Methods

Shashaank Srinivasan
Shashaank Srinivasan
2,440 Points

I've inserted the '#' symbol in quotations, what am I missing in the code?

Any help is greatly appreciated.

app.js
var id = "23188xtr";
var lastName = "Smith";

var userName = "id"+"#"+"lastName" .toUpperCase();
index.html
<!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
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
MOD
Rich Donnellan
Treehouse Moderator 27,696 Points

You're literally outputting "id" and "lastName". Variables will not work with quotes (single or double); remove them from id and lastName.

The 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
Navid Mirzaie Milani
6,274 Points

aaah damn .. i didn't even recognise the mistake ... and those were variables my bad indeed and Charles Lee is right :).

Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,696 Points

It'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!