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 trialJames Joyce
3,551 Pointsconcatenation 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
Treehouse TeacherHi 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!
James Joyce
3,551 PointsJames Joyce
3,551 PointsI 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
Treehouse TeacherJennifer Nordell
Treehouse TeacherJames 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 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