Functions and Procedures: Modular CodeActivities & Teaching Strategies
Active learning works well for teaching functions and procedures because students need to see modularity in action to grasp its benefits. When learners build and call their own reusable blocks, they experience firsthand how organization improves efficiency and clarity in code.
Learning Objectives
- 1Create a simple program using ScratchJr that defines and calls a custom function to perform a sequence of actions.
- 2Compare the length and readability of a program written with repeated code versus one using a defined function.
- 3Explain how defining a function helps to organize a program into smaller, manageable parts.
- 4Justify when it is more efficient to create a new function instead of writing sequential code for a task.
Want a complete lesson plan with these objectives? Generate a Mission →
Pair Build: Reusable Dance Function
In pairs, students create a function block with three dance moves like spin, jump, and wave. They call the function four times in a program, adding sounds each time. Partners switch roles to test and tweak for smoother playback.
Prepare & details
Construct a program that utilizes functions to break down complex tasks into smaller parts.
Facilitation Tip: During Pair Build, circulate and ask pairs to count the total blocks in their programs before and after using functions to highlight the difference in code length.
Setup: Varies; may include outdoor space, lab, or community setting
Materials: Experience setup materials, Reflection journal with prompts, Observation worksheet, Connection-to-content framework
Small Group Challenge: Story Action Modules
Groups define two procedures, such as 'hide behind tree' and 'run to friend,' for a simple adventure story. They sequence calls to build the full narrative, then swap one procedure with another's for a remix. Record observations on efficiency.
Prepare & details
Analyze the benefits of using functions for code reusability and readability.
Facilitation Tip: For the Small Group Challenge, provide a checklist that includes defining modules, testing them, and remixing a peer’s project to emphasize iterative improvement.
Setup: Varies; may include outdoor space, lab, or community setting
Materials: Experience setup materials, Reflection journal with prompts, Observation worksheet, Connection-to-content framework
Whole Class Gallery: Function Share-Out
Each pair creates one unique function for animal behaviors, like 'swim across pond.' Project all on the board for the class to drag into new programs. Discuss which combinations work best and why.
Prepare & details
Justify when to create a new function versus writing sequential code.
Facilitation Tip: In the Whole Class Gallery, invite students to present their functions and explain why they chose to modularize specific actions in their stories.
Setup: Varies; may include outdoor space, lab, or community setting
Materials: Experience setup materials, Reflection journal with prompts, Observation worksheet, Connection-to-content framework
Individual Debug: Fix the Modular Maze
Students receive a maze program with broken function calls. They identify the issue, recreate the 'turn corner' procedure correctly, and test runs. Note before-and-after step counts.
Prepare & details
Construct a program that utilizes functions to break down complex tasks into smaller parts.
Setup: Varies; may include outdoor space, lab, or community setting
Materials: Experience setup materials, Reflection journal with prompts, Observation worksheet, Connection-to-content framework
Teaching This Topic
Approach this topic by having students build small, meaningful functions that solve real problems in their programs. Avoid starting with abstract definitions of functions; instead, let students discover their purpose through repeated use. Teachers should model tracing function calls step by step to prevent the misconception that functions run automatically.
What to Expect
Successful learning shows when students can define a function, call it multiple times, and explain why modular code is useful. They should also compare modular and sequential code, identifying differences in length and readability.
These activities are a starting point. A full mission is the experience.
- Complete facilitation script with teacher dialogue
- Printable student materials, ready for class
- Differentiation strategies for every learner
Watch Out for These Misconceptions
Common MisconceptionDuring Pair Build, watch for students who believe functions are only useful for long programs.
What to Teach Instead
Have students count the blocks in their sequential and modular versions, then ask them to justify why modularity helps even in short programs.
Common MisconceptionDuring Whole Class Gallery, listen for explanations that suggest functions run all code at once.
What to Teach Instead
Ask students to trace the order of blocks step by step when calling a function, using visual cues like pointing to the screen to reinforce sequential execution.
Common MisconceptionDuring Small Group Challenge, notice if students assume functions work without testing.
What to Teach Instead
Challenge groups to intentionally break their functions by changing a value, then fix the errors through peer review, emphasizing that functions require testing like any other code.
Assessment Ideas
After the Pair Build activity, ask students to draw or describe how they used a function to create a dance sequence and write one sentence explaining why using a function helped them.
During the Small Group Challenge, observe students as they define and call their functions. Ask them to point out the function definition and its call site, noting which students can identify and explain these parts.
After the Whole Class Gallery, present two versions of a simple animation: one with repeated blocks for a character’s dance, and one using a 'dance move' function. Ask students which program is shorter and which is easier to understand, and have them explain their reasoning in pairs before sharing with the class.
Extensions & Scaffolding
- Challenge students who finish early to create a function that combines sound and motion, then call it in three different parts of their program.
- For students who struggle, provide pre-written function blocks with blanks to fill in, so they focus on calling the function rather than writing its definition.
- Deeper exploration: Ask students to compare their modular program with a peer’s sequential version and write a short reflection on which they would prefer to debug and why.
Key Vocabulary
| Function | A named set of instructions that performs a specific task. It can be used multiple times in a program. |
| Procedure | Another name for a function, especially when it is a set of steps to follow. In block-based coding, this is often how functions are referred to. |
| Call | To use or run a function that has already been defined. You 'call' the function by its name. |
| Modular Code | Code that is broken down into smaller, independent parts or modules (like functions), making it easier to manage and reuse. |
Suggested Methodologies
More in Creating with Code
Introduction to Block Coding
Students will explore a block-based coding environment and learn to drag and drop blocks to create simple commands.
2 methodologies
Controlling Digital Characters
Students will write simple block-based programs to make digital characters move, change appearance, or make sounds.
2 methodologies
Adding Interactivity: Events
Students will learn to use event blocks (e.g., 'when flag clicked', 'when space key pressed') to make their programs interactive.
2 methodologies
Debugging Our Programs: Finding and Fixing
Developing strategies to identify and correct errors (bugs) in simple block-based programs.
2 methodologies
Advanced Loop Structures and Iteration
Exploring advanced loop structures, nested loops, and iteration techniques to solve more complex computational problems and generate patterns.
3 methodologies
Ready to teach Functions and Procedures: Modular Code?
Generate a full mission with everything you need
Generate a Mission