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

I am finding functions a hard topic to grasp, how can i improve?

I'm ok with variables and loops but this functions thing is hard. I know it is all about creating a program that executes when summoned, but i am still not sure on how to use it.

1 Answer

function are useful when you repeat a process many time, like when you look to your cellphone to see if there are any new messages, that is a use a function to check for new message and display notification periodically.

and if you are comfortable with math...they are exactly the same, to calculate the average ;

  • step -1 - add all values.
  • step -2 - divide the sum on the effectif. to repeat these steps every time you want an average you will create a function;

Functions make our life easier because we don't have to rewrite the same code over and over ...take few minutes and think, about things that you have to repeat in your daily life, you see a pattern and that could be your function.