← Back to Library
Lesson PlanFreeFR

(Francais) C2: Unplugged - Event Handlers

Description Level C, Lesson 2: Students will learn the definition and function of event handlers. Students will use event handlers to “program” their classmates using Dot’s buttons. Objectives Define

(Francais) C2: Unplugged - Event Handlers

Before the Lesson

Prior Experience

Before this lesson, we recommend that students complete:

  • Level A-B Lessons: All
  • Level C: Lesson 1
  • [Optional] Level A-B Challenge Cards: All
  • [Optional] Level C Challenge Cards: C 1.1-1.3

Review

Algorithm Review

  1. Ask, “What is an algorithm?”
    • Sample response: “An algorithm is a series of directions for a computer or robot to follow.”
  2. Ask, “Why is it important that the sequences in the code you write be correct?”
    • Sample response: “Robots only follow the directions you give, so if your sequences are not in the right order, then the robot will not do what you want it to do.”
  3. Ask, “Why do we use loops in our algorithms?”
    • Sample response: “Using loops in our algorithms helps us write code more quickly and easily.”

Events Review

  1. Ask, “What is an event?”
    • Sample response: “An event is an action that causes something to happen.”
  2. Ask, “What kind of events can Dash and Dot sense?”
    • Sample response: “Dash and Dot can sense a button push, sounds, and movements.”

Instruction

Introduction

  1. Watch the Code.org video about event handlers: https://studio.code.org/s/coursec-draft/stage/10/puzzle/1. Then ask:
    • “What are event handlers?” (Sample response: “Event handlers are things that the computer constantly looks for.”)
    • “Why are event handlers important?” (Sample response: “Event handlers allow us to control our program while it is running.”)
  2. Say, “We just watched a video about Nat, who helped program the first Xbox.”
    • Ask, “Why did he use event handlers?” (Sample response: “Nat used event handlers to help make the video games he designed more interesting.”)
    • Ask, “How did Nat use event handlers in his video games?” (Sample response: “Nat used event handlers to make the players on the screen jump and walk forward.”)
  3. Ask, “What is an example of an event handler in your life?”
    • Sample response: “When I hear my stomach growl, I eat a snack.”

Quick Check

  • Why are event handlers important?
  • When are event handlers used? (Sample response: “Event handlers are used throughout programs whenever we want something to happen at the press of a button or the push of a lever.”)
  • Would a video game be interesting to play without event handlers? Why or why not? (Sample response: “No, a video game would not be interesting to play without event handlers because we would have no way to interact with the game. Without event handlers, the game would simply be a sequence of events that we would have no control over.”)

Guided Practice

Activity: Dot's Human Robot

  1. Say, “Today, we are going to use Dot’s buttons to control a human robot.”
    • Select a student volunteer to be the “human robot.”
  2. Show or project the Event Handlers Worksheet and say, “We are going to program the human robot with event handlers. The event handlers will tell the human robot to perform an action each time one of Dot’s buttons is pressed. The button press is an event and what the human robot does is an action.”
  3. Ask the students to decide what action the human robot should do for each button press. Then model filling out the Event Handlers Worksheet with the class’s decisions.
    • For example: If Button 1 is pressed, the human robot will wave his or her hands. If Button 2 is pressed, the human robot will make an animal sound. If Button 3 is pressed, the human robot will spin around. If the Top Button is pressed, the human robot will sing a song.
  4. Have students take turns pressing Dot’s buttons on the Event Handlers Worksheet.
    • After each button press, have the human robot perform the corresponding action.
    • (Optional) If you have a Dot robot, have students press the buttons on the actual robot.
  5. Select different student volunteers to be the “human robot” and repeat the activity in the same manner.
  6. Say, “Using Dot’s buttons as event handlers works very similarly to using a video game controller. Dot is the game controller, and the human robot is the character in the game. When you press one of Dot’s buttons, you create an event that causes the human robot to perform an action.”

Quick Check

  • In this activity, what were the events that happened? (Sample response: “Pressing the buttons.”)
  • What happened after each event? (Sample response: “The human robot performed a different action.”)
  • What kinds of event handlers did we make in the activity? (Sample response: “We had the human robot jump up and down when we pressed Button 1.”)

Educational Standards

CSTA

ISTE

NGSS

Common Core

Wrap Up

Student Presentations

  1. Have student groups take turns sharing their event handlers with the class. Encourage them to:
    • Explain their design thinking (e.g., “We wanted to make the human robot move a lot, so our event handlershad the robot move forward, turn right, and spin”).
    • Share any obstacles and difficulties they overcame during the activity (e.g., “Our human robot had problems seeing what buttons we were pressing, so we called out the button name before we pressed it”).
  2. Encourage students to ask each other how they accomplished different objectives and give each other feedback on their event handlers. Possible questions/feedback includes:
    • “I like how you (had the human robot sing when the Top Button was pressed.)”
    • “What if you (had the human robot sing AND dance when the Top Button is pressed)?”

Follow-Up Questions/Discussion

  • How could you have changed the event handlers to make the human robot perform a dance? (Sample response: “We could have the human robot wiggle when Button 1 is pressed and have the human robot spin when Button 2is pressed. ”)
  • When did you use an event handler in your real life today? (Sample response: “When the bell rang, I put my backpack in my locker.”)

Assessment

  • Use our Evaluation Rubric to review students' work and presentations.
  • [Optional] Share your students' work with the world using @logicsacademy and #dashanddot!

Independent Practice

Instructions

  1. Arrange students into small groups and distribute an Event Handlers Worksheet to each group.
    • (Optional) If available, distribute a Dot robot to each group.
  2. Have students design their own event handlers. Then have students take turns being the “human robot” and the button presser.
    • (Optional) If Dot robots are available, have groups press the actual buttons on Dot when trying out their event handlers.
  3. If time permits, have student groups swap worksheets and try out each other’s event handlers.
  4. Have students use the Wonder Journal: Reflection Worksheets to describe what happened during the activity.
  5. (Optional) Have students use When and My sounds blocks in Blockly to program Dot to call out the assigned action when each button is pressed (e.g., “Spin around!”).