Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Creating a var sentence vs. putting all text in the document.write field
Hi there, I successfully completed this challenge (and even monkeyed with the CSS file a tiny bit), but I did it a bit differently than the video above. I found my code easier to read and write when I just put everything I wanted to appear in the story inside the document.write field instead of creating variables for each sentence and then using "sentence +=".
My question is this: is there a reason it's better to use "sentence +="? Or is it just a matter of personal preference?
So you can see what I mean, here's the snapshot of my code: https://w.trhou.se/56nqrz5m8v
kevin curtis15,287 Points
It's best practice to do it the way it was suggested. One reason being code readability. Another reason being that when you put your code into production you never want to use the document.write function. Here's a thread you can have a read through if you like: https://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice