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 The Variable Challenge Solution

James Joyce
James Joyce
3,551 Points

concatenation specifics

Curious why we don't concatenate multiple variables and strings on the same line. For example: sentence += ' programmer who wanted to use JavaScript to ' + verb + ' the ' + noun + '.</h2>'; vs the video solution sentence += ' programmer who wanted to use JavaScript to ' + verb; sentence += ' the ' + noun + '.</h2>';

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I could be wrong, but I feel like this was done for the sake of clarity in the video. It gets pretty messy to show people the code when the instructors scroll way over to the right and then have to go back. In the videos they tend to like to have everything all on the same screen. It seems like this was a style choice made simply for the sake of clarity as your solution would also work.

Hope this helps! :sparkles:

James Joyce
James Joyce
3,551 Points

I thought they may have been the case, I couldn't get the code to work when I concatenated multiple objects but It's likely there was just a minor syntax error on my part. Just wanted to make sure it wasn't a best practice scenario (i.e. you should not concatenate x number of objects together because of x reason). Thank you for your quick reply :)

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

James Joyce On a side note, as you get further along in the JavaScript track you'll find a workshop on a nifty thing called JavaScript template literals which will make this whole concatenation of strings even less messy. It's "syntactic sugar", but makes the code much more readable :smiley: Actually, if you don't mind taking a detour you might check it out at your leisure. It's pretty short and marked as "beginner" level. You can find it here