Hello there! I am Studyfin, your coding buddy. Today we will learn about functions, which are like magic shortcuts for your code!
A function is a saved block of code. You give it a name so you can use it over and over.
Imagine you want to draw a star. Instead of writing ten steps every time, you make a 'drawStar' function.
Using a function is called 'calling' it. You just write its name, and the computer does the work!
Functions help us solve big problems. We break a big task into smaller, easy-to-read functions.
✏️ Worked example
Let us design a program to draw a happy face using functions. We will break this big task into three smaller steps.
- First, we write a function called drawCircle() to make the yellow face outline.
- Next, we write a function called drawEyes() to place two blue circles inside.
- Then, we write a function called drawSmile() to add a happy curved line at the bottom.
- Finally, we call all three functions in order: drawCircle(), drawEyes(), and drawSmile()!
Want the full interactive lesson — quiz, animations, and Finn cheering them on?