Skip to content

Introduction to Functions

Beginning of the lesson

Introduction to Functions

A named little machine that does one job for you

Big Idea: A function is a reusable, named block of steps. You give it some inputs, it does its steps, and it hands back an output. Once you build a function, you can use it again and again without writing the steps out every time.
By the end you will be able to:
  • say what a function is in simple words,
  • explain inputs and an output,
  • say why we split a big program into small named pieces.

1. What is a function?

A function is a group of steps that we put together, give a name, and use whenever we want. Instead of writing the same steps over and over, we write them once inside a function. Then we just say the function's name to run all of those steps at once.

Think of making toast. The steps are: put bread in the toaster, push the lever down, wait, take out the toast. That is four steps. If we put those steps in a function called makeToast, then next time we only need to say makeToast and all four steps happen. The name stands for the whole block of steps.

A function is a reusable, named block of steps. Reusable means you can use it many times.

2. Inputs and an output

Most functions take some inputs and give back one output.

  • Input = what you put in (the things the function needs to do its job).
  • The steps = the work the function does with the inputs.
  • Output = what comes back out when the function is done.

For example, a function called addTwoNumbers takes two inputs (say 3 and 5), adds them, and its output is 8. Change the inputs and you get a different output: give it 10 and 2, and the output is 12. Same function, same steps, but different results depending on the inputs.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers