Learn about functions and why we use them in programs. Then create some functions of your own using Marty.

21 of 21 linked standards shown.
| Curriculum area | Linked standards |
|---|---|
| Digital Technologies, Design & technologies: Design & Technologies | |
| Digital Technologies, Design & technologies: Digital Technologies |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| General standards |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| Health and Wellbeing: Mental, Emotional, Social and Physical Wellbeing | |
| Literacy & English: Listening and Talking | |
| Literacy & English: Writing | |
| Technologies: Computing Science |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| Computing, Design and Technology: Computing | |
| Computing, Design and Technology: Design and Technology |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| International Society for Technology in Education (ISTE) |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| Middle School Technology Applications: Grade 6 to Grade 8 |
Select a code to read the full standard.
In this lesson, learners will be introduced to functions and explore how they are used to organise and simplify code. Functions are a fundamental programming concept that reduce repetition by grouping together a set of instructions to perform a specific task.
Learners will begin by reflecting on games they have played before and identifying repeated actions or tactics. This draws a parallel between these patterns and functions in a program. They will then apply this understanding in Blocks by either refactoring existing code into reusable functions or extending projects using pre-built functions already available in the platform.
Experience using sensors and variables
| Timing | Activity | Possible adaptations |
|---|---|---|
| — | Warm upAsk learners to think about playground games they have played. Can they remember a game they regularly won because they discovered a good tactic, or one where another player always seemed to win using the same strategy? Did it ever feel like they had a "secret trick"? Some examples include
Using “Duck, Duck, Goose” as an example, discuss the different strategies for each role in the game. For someone sitting in the circle:
For the person walking around the circle:
Explain that these strategies are similar to **functions** in programming. Each role has a specific set of actions that can be repeated whenever that role is performed. Rather than writing those actions over and over again, programmers group them into functions that can be reused whenever needed. Working in small groups, ask learners to choose one playground game and research the rules if necessary. They should identify:
|
| Timing | Activity | Possible adaptations |
|---|---|---|
| — | Get learningOnce groups have chosen a tactic, ask them to write it as pseudocode and give it a meaningful function name. They should then explain where that function would fit within the overall "program" of the game and describe how it could be reused throughout the game. Invite each group to share their function with the class. Next, introduce My Blocks in Blocks, explaining that this is where learners can create their own reusable functions. Demonstrate Marty's Walk Forward command several times, encouraging learners to observe the individual movements that make up a single walking action. Learners should then open the Marty Controller and repeatedly use the walk command, slowing the movement if necessary. Challenge groups to identify the sequence of individual actions that combine to create a walk and discuss how these could be grouped into a single reusable function. Allow time for learners to compare their ideas before discussing the sequence together. | — |
| — | Time for practiceNext, ask learners to investigate the Kick action. Encourage them to watch the movement several times and identify each step in the sequence. They should pay particular attention to the timing of movements and notice where actions happen one after another or at the same time. |
| Timing | Activity | Possible adaptations |
|---|---|---|
| — | Cool downBring the class back together and invite groups to demonstrate their work, explaining how their functions operate and why they structured them in that way. Encourage classmates to ask questions and compare different approaches. Use the following questions to support discussion:
Finish with your usual end-of-lesson routines before asking learners to log off their devices and tidy away their equipment. | — |
| — |
As learners work, circulate and ask questions such as:
If possible, encourage learners to observe other groups' ideas and discuss the different ways they approached the task.
Allow time for groups to demonstrate the functions they have created. Discuss how much longer it would take to program movements such as dancing if every individual step had to be recreated each time, reinforcing that reusable functions save time, reduce repetition and make programs easier to understand.
| — |