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

EDDY saqchez
EDDY saqchez
635 Points

how do I Create a variable named fullName that combines both the first and last name variables to create a string like "

var fullName = "firstName" + " lastName.";

var firstName = "Eddy";
var lastName = "Sanchez";
var Fullname = "Eddy" + "Sanchez".;
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

2 Answers

Alejandro Narvaja
Alejandro Narvaja
Courses Plus Student 7,340 Points

Hi, the approach you have is wrong. The final point of the Fullname variable should not be there, delete it.

After that, the variable will work, but you must use its two variables firstName and lastName to complete Fullname. For example:

var firstName = "Eddy";
var lastName = "Sanchez";
var Fullname = firstName + " " + lastName;

One tip is that the variable Fullname use camelCase, staying like this:

var fullName = firstName + " " + lastName;

Finally, it will work with that, but you can only see it in the console. If you want it to look in HTML, you should add this to your JS file.


I hope you serve, greetings!

Olga DC
Olga DC
16,680 Points

Hi Eddy. To create the new variable fullName, you have to use the two variables that you already have (firstName and lastName), and not their values. Although the result would be the same, imagine when you want to change the value of firstName and lastName variables, you would have to manually change fullName too, and that has no sense. If you set the value of fullName to be a compound value from the other two, it will automatically change when the other ones change.