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 Loops, Arrays and Objects Tracking Data Using Objects Accessing Object Properties

Why does he not open the paragraph tag and only ends it with </p> how is that possible?

In this video we are using the following code -->

message += person.skills.join(', ') + '</p>';

I am curious, why does he not open the paragraph tag? It seems like he only closes the tag with </p> like you would with any HTML code, but nowhere is the opening <p> to be found.

Thank you teamtreehouse!

2 Answers

Ryan S
Ryan S
27,276 Points

Hi Edin,

When using the addition assignment operator (+=) you can keep adding on to the value of a variable instead of replacing it. So when concatenating a long string, you can do it in pieces instead of ending up with one long line.

In this case, the opening paragraph tag was defined on the previous line and it was completed in the final line using addition assignment.

message += '<p>I have ' + person.skills.length + ' skills: ';
message += person.skills.join(', ') + '</p>';

Hope this clears things up.

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

or we can use this, it works fine as well: probably just another way of using "message +="

message += '<p>I have ' + person.skills.length + ' skills: </p>'; 
message += person.skills.join(', ') ;