Computer Science Grade 3 20 min

Function Challenge: Building a Complex Program

Students will be challenged to build a complex program using functions to demonstrate their understanding.

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define a function as a reusable block of code that performs a specific task. Create a new function in a block-based coding environment. 'call' a function to run its code within a larger program. Combine two or more functions in a sequence to create a more complex program. Explain that functions help make code shorter, more organized, and easier to read. Identify and fix a simple bug in a program that uses functions. Have you ever built a giant LEGO castle using smaller, pre-built towers? 🏰 What if we could build big computer programs using smaller, pre-built code blocks? Today, we're going to learn about a coding superpower called 'functions'! Functions are like special recipes for our computer that we can use over and over agai...
2

Key Concepts & Vocabulary

TermDefinitionExample FunctionA named block of code that does one specific job. Think of it as a 'code recipe'.A function named `drawSquare` that holds all the blocks needed to make a character draw a perfect square. Define a FunctionThe process of creating a new function, giving it a name, and adding the instruction blocks inside it.Using the 'Make a Block' button in Scratch to create a new pink block called `jump` and putting the 'change y' blocks inside it. Function CallThe action of using a function in your program. This tells the computer to run the code stored inside that function.Placing your custom `drawSquare` block under the 'when green flag clicked' event block. Reusable CodeInstructions that can be used many times in a program without ha...
3

Core Syntax & Patterns

Define Before You Call You must create (define) your function before you can use (call) it. The computer needs to know the recipe (the function definition) before you ask it to cook (call the function). In block coding, the function's definition block is usually kept off to the side. One Job, One Function Each function should be responsible for only one specific task. A function to make a character jump shouldn't also make it say 'hello'. Keeping functions simple makes them easier to understand, fix, and reuse. Give Good Names Function names should be clear and describe what the function does. Name a function `drawCircle` instead of `block1` or `doStuff`. This makes your code like a story that is easy for you and others to read.

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
You are making a program with three different animals: a cat, a dog, and a bird. Each animal needs to be able to eat and sleep. What is the most efficient way to code their actions using functions?
A.Write separate functions for every action, like `cat_eat`, `cat_sleep`, `dog_eat`, `dog_sleep`, etc.
B.Create two functions, `eat()` and `sleep()`, that can be used by any animal character.
C.Write one very long function that has all the actions for all the animals inside it.
D.Don't use functions, just copy and paste the code for eating and sleeping for each animal.
Challenging
A program draws a picket fence by repeating 4 lines of code 20 times to draw 20 pickets. This makes the program 80 lines long. How could using a function make this program better?
A.function `draw_picket()` would make the program shorter and easier to change the look of all pickets at once.
B.function would make the fence draw much faster.
C.function would change the color of the fence automatically.
D.Using a function would make the program longer, not shorter.
Challenging
A function `celebrate()` calls another function `play_music()`. The `play_music()` function then calls a third function `flash_lights()`. If a programmer changes `flash_lights()` to make the lights flash blue instead of red, what will happen when `celebrate()` is called?
A.Nothing will change because only the `flash_lights` function was edited.
B.The music will be different, but the lights will stay red.
C.The program will crash because of the change.
D.The celebration will happen, music will play, and the lights will now flash blue.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Function Fiesta: Introducing Reusable Code Blocks

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.