Lesson 6: Patterns & Functions
A function is a named group of instructions that you can use over and over again. Instead of writing the same steps 10 times, you define them once as a function — and just call the function's name whenever you need those steps!
Key Concepts
What Is a Function?
A function is like a mini-program within your program. You give it a name, and it remembers a set of instructions. When you need those instructions, just call the function by name.
Reusing Code
Functions save you from repeating yourself. Instead of writing 'draw a house' 5 times (20+ steps each), you define a drawHouse() function once and call it 5 times.
Functions Take Inputs
You can give functions inputs (called parameters) to customize what they do. drawCircle(size, color) can draw a big red circle or a tiny blue one — same function, different inputs!
🆕 Activity: Function Painter
Each button calls a 'function' to draw a shape. Combine them to create your own artwork! Try calling the same function multiple times.
✅ Check Your Understanding
1. What is a function in coding?
2. Why are functions helpful?
3. drawCircle(size, color) is a function that takes: