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

Not sure how to combined the variables

I am not sure how to add uppercase and combined these two variables. I have tried a few different methods but nothing seems to be working

app.js
var id =("23188xtr");
var lastName = id.toUpperCase ("#+ Smith");
id.toUpperCase ("id + lastname")

var userName = id.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>
Robert Schaap
Robert Schaap
19,836 Points

Leave the original variables, they're fine. String methods can be chained easily. So "john" + "smith" will output as "johnsmith". Same thing goes for the .toUpperCase() method which you can put at the end of a string.

var id = "23188xtr";
var lastName = "Smith";

var userName = id.toUpperCase();

Your last line in app.js will convert id to uppercase just fine. Now you just need to add a hash, and then add the lastName variable converted to uppercase. It looks a bit strange but you can do it all on one line. "string" + stringVariable.method() + "string" is perfectly fine.

1 Answer

Steven Parker
Steven Parker
231,269 Points

To join strings by concatenation, the "+" symbol must appear between the strings instead of inside them.