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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Andy tran](https://secure.gravatar.com/avatar/b6341fae814158ad4f20f43b22bad2d3?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Andy tran
7,112 PointsPlease help clarify why we need to create a function print(message) for a single command like document.write(message)?
In the video, Dave says we should create a function print(message) with a document.write(message) inside it because it will not affect the other codes that call that function. He also says if we have a script that calls that function in 20 different places-and when we need to improve our code, we just need to change the document.write(message) without going to 20 different places. Can someone please explain again the purpose for creating this function print(message)? Thanks!!
1 Answer
![Mark Truitt](https://secure.gravatar.com/avatar/f515835cb09039fa0ffbb6d333cb9c4b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Mark Truitt
8,758 PointsThink of it like this.
Say your currently message is Congrats! You got this answer right but you wanted it to be Congratulations! You got this answer right.
Calling a function that generates this requires you to up date it in one spot. If you just did document.write for each one and the quiz is five questions long. Its not a big deal right?
Now imagine this quiz is 500 questions long. You would have to do a find and replace and adjust it that way or go through and manually change them all. it also affects readable of the code.
Lot easier to understand that message returns you got this question wrong or you got this message right vs seeing if else for 500 questions.