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

Cheri Watts
Cheri Watts
658 Points

Javascript Concatenation Question

Where am I wrong?

app.js
var id = "23188xtr";
var lastName = "Smith";
var userName
userName = id.toUpperCase();
userName += '#' + '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>

1 Answer

Erik McClintock
Erik McClintock
45,783 Points

Cheri,

You have a couple of minor syntax errors here that are easy to make, and unfortunately more difficult to spot! Let's take a look:

You have two issues that I see:

var id = "23188xtr";
var lastName = "Smith";
var userName // issue #1
userName = id.toUpperCase();
userName += '#' + 'lastName.toUpperCase(); // issue #2

Issue #1: Firstly, in this case, it is not necessary to declare your userName variable and set your variable on separate lines; you can easily do this all on one line right out of the gate: var userName = id.toUpperCase();. It isn't technically WRONG to first declare and then separately set your variable, but if you are going to do that, you'll want to make sure you close every statement with a semi-colon. In this case, your variable declaration (i.e. var userName) is missing a closing semi-colon.

You have:

// notice there is no semi-colon after 'userName'
var userName

You want:

// notice there is now a semi-colon after 'userName'
var userName;

Issue #2: You have an extra single quote just before "lastName" here. Remove that quote, and this line is good to go.

You have:

// notice the extra single quote (i.e. ' ) just before "lastName"
userName += '#' + 'lastName.toUpperCase();

You want:

// notice the single quote (i.e. ' ) has been removed before "lastName"
userName += '#' + lastName.toUpperCase();

Other than those two small errors, things look good! One of the most troublesome parts of any programming language is making and finding these tiny errors. They will happen all the time, and are among some of the most difficult things to debug, because they're so easy to miss!

Hope this helps!

Erik

Cheri Watts
Cheri Watts
658 Points

Erik,

Thank you greatly!!! I am a 'newb' to this world and these type errors must be eradicated for me to achieve my programming goals. I bet Treehouse pays you the big bucks and I can see why!!!

Thank you for providing with the impetus to not give up.

:)

Cheri

Erik McClintock
Erik McClintock
45,783 Points

Absolutely, Cheri; it's my pleasure! I and the other moderators are just other students that are a little further along and have the drive and passion to help others succeed when difficulties arise! Our payment is the joy we get from helping our fellow students overcome obstacles and continue down their paths towards becoming better programmers!

Happy coding!

Erik

Cheri Watts
Cheri Watts
658 Points

Erik,

Impressive!

Cheri