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 DOM Scripting By Example Improving the Application Code Refactor 2: Readable Branching Logic

Tony Minseok Kim
seal-mask
.a{fill-rule:evenodd;}techdegree
Tony Minseok Kim
Front End Web Development Techdegree Student 11,682 Points

In real life situation, or workplace situation

So Guil just put all the codes into a function, so that it is more readable and easy to use it over and over again, but I was just wondering when it comes to a real life situation, do you guys usually make functions first or just like Guil, make functions after once you find repeating code lines.

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

In the "real-world" it's normally a bit of both. In general, you will be using and creating many functions. But there may be some instances where you find a lot of code repeated in multiple places in your codebase. Instead of just leaving them there, in an effort to be DRY (Don't Repeat Yourself), the common code is generally extracted into a new function.