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

toUpperCase? Help plzzz

i nkow i need to clean up the code but can someone elaborate on whta im ment to do here.????? thanks in advance

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

var userName = id.toUpperCase();
lastName
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>

2 Answers

Task: Assign an all uppercase version of the id variable to the userName variable.

On the last line, you have quotes around id and lastname.toUpperCase(). Remove those, and that statement should work fine. The two lines above that statement are unnecessary.

John Collom
John Collom
12,143 Points

All you need to do is use string concatenation like you are now. The problem is that you are reassigning the userName variable, causing your first instance of the variable userName = id.toUpperCase(); to get overwritten. Your code will run userName as 23188xtr#SMITH.

Try

var userName = id.toUpperCase() + "#" + lastName.toUpperCase();

Also, as Dave pointed out, remove the quotes on the variables. Otherwise, they will just be interpreted as strings instead of containers holding values.

Do that, fix your syntax errors, and you should be golden!

i tried ,when you say fix the syntax im assuming you mean the whole code?

John Collom
John Collom
12,143 Points

As Dave pointed out, the two lines above are unnecessary.

You can either rewrite the userName variable to:

var userName = id.toUpperCase() + "#" + lastName.toUpperCase();

or keep your first instance of userName and append to it like this:

var userName = id.toUpperCase();
userName += "#" + lastName.toUpperCase();