← Back to Library
Lesson PlanFreeEN

E5: Functions - Part 2

Students will use functions and combine them with event handlers and loops. They will use Blockly preset programs and Challenge Cards to practice their new skills.

Gr. 4–4
E5: Functions - Part 2

Lesson

Overview

Description

Students will use functions and combine them with event handlers and loops. They will use Blockly preset programs and Challenge Cards to practice their new skills.

Objectives

  • define a function

  • design a program that combines event handlers, loops, and functions into a program

  • use functions to revise code and complete coding challenges in an iterative process

Before the Lesson

Prior Experience

It is recommended that students complete:

  • Level A-D Lessons: All

  • Level E: Lesson 1-4

  • [Optional] Level A-D Challenge Cards: All

  • [Optional] Level E Challenge Cards: E 1.1-3.3

You can purchase our Learn to Code Challenge Card sets and Curriculum Guide here: https://store.makewonder.com/#/education

Preparation

  • Fully charge the tablets and robots.

  • Install the Wonder Workshop Blockly app on each tablet.

Review

Functions

Briefly review how students used functions during the previous lesson by asking:

  • "How are functions different from loops?" (Sample response: "Loops repeat bits of code consecutively, while functions repeat bits of code in many different places.")

  • "What is the purpose of functions?" (Sample response: "Functions help make programs more efficient by allowing us to repeat bits of code throughout the program.")

Code.Org Connections (Optional)

  1. Say, "As we level up our coding skills, we have to put everything we've learned together to complete challenges. You need to think about what needs to be accomplished step by step, and try to use a growth mindset. A growth mindset is when you think about your mistakes as ways to learn and grow. Mistakes in a growth mindset are thought to be positive learning experiences."

  2. Review Code.org's lesson focusing on functions and loops: https://studio.code.org/s/coursee-draft/stage/7/puzzle/1

  3. Point out how students needed to use both functions and loops to complete the lesson. Ask, "What was difficult about this task?"

    • Sample response: "It was difficult to follow the different parts of the code. I wasn't sure what would happen next."

Direct Instruction

Introduction

  1. Say, "We have done a couple activities using functions. Now we are going to combine functions with some other familiar coding concepts like loops and event handlers."

  2. Review a real-life example where you could use all these concepts together:

    • When you go to the store, you use a loop to walk through the store: walk up an aisle, turn right/left and then repeat. Once you are in the aisle, you use an event handler. You keep walking until an event happens, such as seeing something that's on your shopping list. When the event happens, you call a "pick up" function: reach out your hand, pick up the object, pull your hand back, put the object in the cart.

Quick Check

  • Ask, "What is a loop?" (Sample response: "A loop is a piece of code that repeats.")

  • Ask, "How do you use event handlers?" (Sample response: "An event handler waits for an event to occur before running the program under it.")

Guided Practice

Activity: Tickle Tackle

  1. Project your tablet screen, open the Blockly app, and go to the menu at the top left of the screen.

  2. Go to the Create New Project menu and select the Tickle Tackle preset program. Then tap "create."

    Tickle Tackle
  3. Say, "Let's see how Blockly uses both functions and event handlers in the Tickle Tackle preset program."

    • Ask the students to look at the program and predict what they think will happen when it is run.

    • Run the program to see if the students' predictions were correct.

  4. Ask, "How many event handlers can you find in this program?"

  5. Have student volunteers describe what happens when the program starts

    • Possible response: "Dot says, 'How do you do?'"

  6. Ask, "How would you make this program work for Dash instead of Dot?"

    • Possible response: "Change each event handler to Dash events. Change sound and animation blocks to Dash's sounds and animations."

  7. Say, "Now I want the function to be called twice for one of the event handlers. What event handler should we change?" (Sample response: "Button 2.")

    • Have a student volunteer add another Call Function block under the selected event handler and then press play to see how the program changed.

Quick Check

  • How many functions can you add in one program? (Sample response: "You can add an unlimited number of functions.")

  • If you use more than one function, how does your program know which one to "call"? (Sample response: "You assign each function a different name so that when you call the function, the program knows which one you want.")

Independent Practice

Instructions

Have students work on the following activities in small groups (ideally 2-3 students per robot).

Encourage students to share tablet and robot time. Have them establish and rotate through roles such as:

  • Lead Programmer: Holds the tablet and manipulates the code.

  • Robot Wrangler: Retrieves and resets the robot after every program attempt.

  • Documentarian: Records group results, thoughts, and progress. Illustrates group designs and ideas.

When students work together while coding, they're able to help each other identify mistakes and develop creative solutions!

Tickle Tackle - Extension

  1. Have students use the Wonder Journal: Dot Planning or General Planning worksheet to design ways to add to or alter the Tickle Tackle preset program. They can:

    • Change the function or add more functions.

    • Change or add lights, movements, and sounds in each function.

      • Add a loop.

    • Change the cues.

  2. After they finish revising the program, have students:

    • Complete a Wonder Journal: Reflection worksheet.

    • Take a screenshot of their Blockly code.

    • Take a video of Dot while the code is running.

Challenge Cards (Optional)

  1. You can purchase our Learn to Code Challenge Card sets and Curriculum Guide here: https://logicsacademy.com/store/

  2. Have students complete the following Challenge Cards:

    • E 3.4: Dog Trainer

    • E 3.5: Tricks Galore

    • E 3.6: Obstacle Course

  3. For each challenge, encourage students to:

    • Use the Wonder Journal: Dash Planning or General Planning worksheets to discuss how they can complete the challenge.

    • Review the Troubleshooting and Problem Solving & Debugging worksheet if they run into any problems with their code.

  4. After they finish each challenge, have students:

    • Complete a Wonder Journal: Reflection worksheet.

    • Take a screenshot of their Blockly code.

    • Take a video of Dash while the code is running.

    • Update their Challenge Card Checklists.

Wrap Up

Student Presentations

  1. Have student groups take turns sharing one of their programs with the class. Encourage them to:

    • Explain their design thinking (e.g., "We wanted to add (another function) to the program because . . .," "We changed actions in the function blocks here to solve the challenge because . . .").

      • Share any obstacles and difficulties they overcame during the activity (e.g., "At first, we weren't sure about the best place to add a loop, but then we ran the program a few times with the loop in a variety of locations to find the best place to put it").

  2. Encourage students to ask each other how they accomplished different objectives and give each other feedback on their programs. Possible questions/feedback includes:

    • "How did you (add another function)?"

    • "I like how you (added the loop)."

    • "What if you (changed the cues)?"

Follow-Up Questions/Discussion

  • Why are functions important? (Sample response: "Functions help repeat non-consecutive sequences of code.")

  • How was your program affected by loops? (Sample response: "Loops allowed me repeat bits of code over and over.")

Assessment

  • Use our Evaluation Rubric to review students' work and presentations.

  • [Optional] Share your students' work with the world using @logicsacademy and #dashanddot!

Educational Standards

CSTA

CSTA

  • 1B-AP-10: Create programs that include sequences, events, loops, and conditionals.

  • 1B-AP-12: Modify, mix and incorporate portions of an existing program into one's own work to develop something new or add more advanced features.

  • 1B-AP-16: Take on varying roles, with teacher guidance, when collaborating with peers during the design, implementation, and review of program development.

ISTE

ISTE

  • 4d: Exhibit a tolerance for ambiguity, perseverance, and the capacity to work with open-ended problems.

  • 5a: Formulate problem definitions suited for technology-assisted methods such as data analysis, abstract models and algorithmic thinking in exploring and finding solutions.

  • 6b: Create original works or responsibly repurpose or remix digital resources into new creations.

  • 7c: Contribute constructively to project teams, assuming various roles and responsibilities to work effectively toward a common goal.

NGSS

NGSS

  • 3-5-ETS1-2: At whatever stage, communicating with peers about proposed solutions is an important part of the design process, and shared ideas can lead to improved designs.

  • 3-5-ETS1-3: Tests are often designed to identify failure points or difficulties, which suggest the elements of the design that need to be improved.

Common Core

Common Core

  • CCSS.ELA-LITERACY.W.2.6: With guidance and support from adults, use a variety of digital tools to produce and publish writing, including in collaboration with peers.

  • CCSS.ELA-LITERACY.W.2.8: Recall information from experiences or gather information from provided sources to answer a question.

  • CCSS.ELA-LITERACY.SL.3.1: Engage effectively in a range of collaborative discussions (one-on-one, in groups, and teacher-led) with diverse partners on grade 3 topics and texts, building on others' ideas and expressing their own clearly.

  • CCSS.ELA-LITERACY.SL.3.3: Ask and answer questions about information from a speaker, offering appropriate elaboration and detail.

  • CCSS.ELA-LITERACY.SL.3.4: Report on a topic or text, tell a story, or recount an experience with appropriate facts and relevant, descriptive details, speaking clearly at an understandable pace.

Alberta - Grade 4 - ICT

Grade 4

ICT

C5: Students will use technology to aid collaboration during inquiry.

C6: Students will use technology to investigate and/or solve problems.

F6: Students will demonstrate a basic understanding of the operating skills required in a variety of technologies.

Ontario - Grade 4 - Mathematics

Grade 4

Mathematics: Algebra (Coding)

C3.1 solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves sequential, concurrent, repeating, and nested events

Nova Scotia - Grade 4 - ICT

Grade 4

ICT

P2: Students will be expected to use digital tools to develop ideas and original works in innovative ways.

TOC1: Students will be expected to 

  • safely use many forms of current technology for learning with growing competence 

  • demonstrate conceptual understanding of how information and communication technology, digital tools, and authorized networks support their learning 

  • use terminology related to information and communication technology

British Columbia - Grade 4 - ADST

Grade 4

ADST

• Make changes and test again, repeating until satisfied with the product 

• Use materials, tools, and technologies in a safe manner, and with an awareness of the safety of others, in both physical and digital environments 

• Identify the skills required for a task and develop those skills as needed 

• Use familiar tools and technologies to extend their capabilities when completing a task 

• Demonstrate a willingness to learn new technologies as needed