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 Combining Strings

Neslee Rodillo
Neslee Rodillo
19,615 Points

I don't see where the fullName variable is going wrong

On the Stage 2: Storing and Tracking Information with Variables challenge, Task 3 of 3, I don't see where the code I entered is not working, can anyone clarify where I am going wrong with relation to the spacing

Challenge Task 3 of 3: Create a variable named fullName that combines both the first and last name variables to create a string like "Mary Jones".

My solution:

''' var fullName = 'Nez ' + ' Rod'; '''

Result:

Bummer! This creates the string 'Nez Rod'. There should be an empty space character -- ' ' -- between your first and last name.

script.js
var firstName = 'Nes';
var lastName = 'Rodillo';
var fullName = ' Nes ' + ' Rodillo ';
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="script.js"></script>
</body>
</html>

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

What you should do is concatenate firstName and lastName together with space in between.

var fullName = firstName + " " + lastName;
Neslee Rodillo
Neslee Rodillo
19,615 Points

Thank you William, the error explanation didn't explain it all that well. I thought the values of the variables had to be added as well as speech marks to both sets of values.

e.g. var fullName = "Nez " + " Rod";

William Li
William Li
Courses Plus Student 26,868 Points

Neslee, yeah, your way of doing it isn't wrong, and would produce the same output too, but ultimately, that approach is not what this challenge is looking for.

combines both the first and last name variables to create a string

so yeah, the purpose of this challenge is to test you on how to make use of defined variables, by combining them to make a new string.