Studyfin Studyfin ✨ Sign up free

Functions

Grade 6 · Coding · Free lesson

Hi there! Today we are going to learn about functions. Think of them as magic machines that save your time!

In coding, a function is a named block of code. It does one specific job whenever you ask it to.

mathematics

Instead of writing the same steps over and over, you group them. You give that group a simple name.

FUNCTION

To use a function, you just call its name. This makes your code neat, short, and easy to read.

CALLAction Happens!
✏️ Worked example

Let's write a function that greets a user. Instead of typing 'Hello!' and 'Welcome!' three times, we will make one function.

  1. First, we define our function. We will name it 'sayHello'.
  2. Next, we write the steps inside it: print 'Hello!' and print 'Welcome!'.
  3. Now, our function is saved in the computer's memory, waiting to be used.
  4. Finally, we call the function by writing 'sayHello()' three times in our code.
  5. The computer runs our saved steps each time, greeting three different users easily!
to learn
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons