Module 4 · Functions · Lesson 1 of 4
What is a function, and why?
A function is a named block of code that does one job. You define it once, then call it by name whenever you need that job done — like a little machine you can run again and again, with different inputs each time.
Why bother? Imagine greeting three people without a function: you'd copy the same lines three times. Now imagine fifty people — or wanting to change the wording. You'd be editing every single copy, and missing one is how bugs are born.
A function fixes all of that. Write the steps once, give them a name, and call it. Three lines of definition replace the copy-paste, the code says what it means (greet), and a change in one place updates every call.
That's the whole promise of functions: don't repeat yourself, name your ideas, and keep each job in exactly one place. Next we'll see how they let you break a big problem into pieces.