Studyfin Studyfin ✨ Sign up free

Functions

Grade 5 · Coding · Free lesson

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.

Function: drawStar()

Using a function is called 'calling' it. You just write its name, and the computer does the work!

Call: drawStar()

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.

  1. First, we write a function called drawCircle() to make the yellow face outline.
  2. Next, we write a function called drawEyes() to place two blue circles inside.
  3. Then, we write a function called drawSmile() to add a happy curved line at the bottom.
  4. Finally, we call all three functions in order: drawCircle(), drawEyes(), and drawSmile()!
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons