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

Darko Brodski
Darko Brodski
785 Points

I'm stuck on this guys, help. I don't know where to add# symbol and how to combine those?

I tried several times, but i dont know where to add + and how to combine those.

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

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

The second challenge is to update the userName variable so that the "#" and an uppercase version of the last name are appended to the value in the first task (which you have already in your answer above). The sample final output is also provided.

Cody Reed
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Cody Reed
Front End Web Development Techdegree Graduate 19,268 Points

Anytime you'd like to add to or combine a variable with a new expression, such as (1 + 'fox') you would use an assignment operator like: userName += 1 + 'fox'; . Hope this helps point you in the right direction. Check out this article for further information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators

1 Answer

Russ Perry
Russ Perry
13,418 Points

To concatenate strings, you just add a plus in between the variables. I don't know what your goal is with this but I will give you an example

let firstName = 'Sam';
let lastName = 'Davis';

let fullName = firstName + ' ' + lastName;

the quotes in between firstName and lastName add the space between the names.