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 trialAlsaig Sandra
Front End Web Development Techdegree Graduate 15,434 PointsQuestion regarding the last 3 lines.
Hi all! So, I had to concatenate the last 2 lines of the code (above the print(message) call) to make sure it looks like Dave's on the browser. (using Chrome)
I know it isn't a big deal, but I feel like I need to know why that is.. ππ€
Thanks in advance for any help..
Have a great day & Happy coding!!! π»ππΌ
var person = { name : 'Sarah', country : 'US', age : 35, treehouseStudent : true, skills : ['JavaScript', 'HTML', 'CSS'] }; function print(message) { var div = document.getElementById('output'); div.innerHTML = message; } var message = "<p> Hello. My name is " + person.name + "</p>"; message += "<p> I live in the " + person.country + "</p>"; person.name = "Rainbow Dash"; message += "<p> But I wish my name was " +person.name + "</p>"; person.age += 1; message += "<p> My age is now " + person.age + "</p>";
ππΌmessage += "<p> I have " + person.skills.length + " skills: " + person.skills.join(", ") + "</p>";
print(message);
2 Answers
furkan
11,733 PointsActually he has concatenated the last two strings. On the message variable he has used a += then written the paragraph. The += signs are used frequently in JS for a number of reasons of which one of the reasons is to take a set of strings and put them together.
Check out this link for some detail:
furkan
11,733 PointsConcatenating means joining up strings. If you dont concatenate the above strings then it would just be treated as separate lines. By adding the strings together, it will treat it as a single complete string. I hope that made sense.
For example, lets suppose I had two variable:
var string1 = "Hello my name is";
var string2 = "furkan";
/* No concatenation and the strings will be treated separately. But I want to concatenate the two so it says "Hello my name is furkan"... So, you can use the plus operator (+) to join the two strings up */
Alsaig Sandra
Front End Web Development Techdegree Graduate 15,434 PointsHi Furkan, I was more wondering how come Dave didn't have to concatenate them and still ended up with those 2 lines as 1.