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

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,925 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,925 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