Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Combining Strings

could you please help me out with this?

i got confused!!!

script.js
var firstName = "Jawad";
var lastName = "Wahedi";
var fullName = "message";
message += "Jawad Wahedi";
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>

2 Answers

Mike Schaming
Mike Schaming
13,901 Points

Hi Jawad! You are on the right track! Your first two steps are spot on: var firstName = "Jawad"; var lastName = "Wahedi";

Once we get to task 3, it's asking us to combine the info stored in the first two variables into a new variable. To combine, we just need to use the "+"

ex. var example = variable1 + variable2;

Hope this helps!

Hi Mike Thank you for the answer. actually i tried this: var firstName = "jawad"; var lastName = "Jawad"; var fullName = "hello"; fullName += "Jawad Wahedi";

and it worked but honestly i didnt get it, how it worked?

Mike Schaming
Mike Schaming
13,901 Points

Hi Jawad,

Yes! It looks like that will work as well. Here's why I think it works too

You created a 3rd variable, var fullName = "hello".

Currently, the only thing stored in this variable is the string "hello

then, you use "+=" which takes whatever is currently stored in fullName, in this case 'hello", and adds the string 'Jawad Wahedi'.

now, fullName should have this: "hello Jawad Wahedi".

This gives us a similar result of : var fullName = firstName + lastName; In this case, we are just adding together whatever strings are stored in firstName and lastName, which are just "Jawad" & "Wahedi".

At least that is what I think is happening. Hope this helped and hasn't added to any confusion. Looks like two different approaches for a similar result.

All the best!

thank you it really helped me to understand. Regards