Events: Programs That React to What the User Does · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Programs that wait for you

Computing · Computing Fundamentals · ages 12-13
Name ______________________   Date ____________
  1. What is an event handler?

    • Instructions that run only when their event happens
    • The power cable of the computer
    • A list of all programs installed
  2. An event handler runs all the time, even before its event happens.

    Circle one:   True   False

  3. A sprite moves when you press the right arrow. Which handler runs?

    • The click handler
    • The arrow-key handler
    • Both handlers at once
  4. In a homework app, you can type answers into boxes, but nothing happens until you press the Submit button. Pressing Submit is what makes the program process your answers. In an event-driven program, what is the button press?

    • An event that runs the handler
    • A mistake the program has to fix
    • A loop that runs the code over and over
    • A comment that the program ignores
  5. You want a sprite to change colour on a click, but it changes when you press a key instead. What is the most likely cause?

    • The sprite is the wrong colour
    • The wrong event
    • The keyboard is unplugged
  6. Why does an event-driven game look like it is doing nothing on the start screen?

    • It waits for your event
    • It is broken
    • It deleted its own code
  7. A program waits with a handler attached to a Submit button. You type into an answer box but never press the button. True or false: the handler code runs while you are typing.

    Circle one:   True   False

  8. Clicking the green button should change the text colour, but nothing happens. The handler is on the red button. What is wrong?

    • The text is too short
    • The screen is too bright
    • The wrong object
  9. Space should make a sprite jump, and a click should turn it blue. A tester presses Space and the sprite turns blue without jumping. What happened?

    • Space is not an event
    • Blue is not a colour
    • The jump handler runs the colour code, or handlers are crossed
  10. A button should turn green only after you type your name, but it is green at once. What would you check?

    • Whether green is pretty
    • Whether the handler tests the input before changing colour
    • Whether the mouse works
LightMySky · lightmysky.comW1-mt_HFtGUhZHz4-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Programs that wait for you W1-mt_HFtGUhZHz4-s1

  1. Instructions that run only when their event happens · A handler waits for its event and runs only then.
  2. False · A handler waits quietly and runs only when its event happens.
  3. The arrow-key handler · The key press fires the key handler, while the click handler keeps waiting.
  4. An event that runs the handler · The button press is an event. The program waits quietly, and only when the event happens does the attached code run.
  5. The wrong event · A handler tied to the key event fires on keys, not on clicks.
  6. It waits for your event · The program listens for your key press or click before it acts.
  7. False · A handler runs only when its event happens. Typing is not the event the handler was attached to, so the handler stays asleep.
  8. The wrong object · The handler listens on the red button, so clicks on green never reach it.
  9. The jump handler runs the colour code, or handlers are crossed · The wrong code sits under the Space event, so the handlers are crossed.
  10. Whether the handler tests the input before changing colour · The handler must test the input, or the colour changes with no typing at all.
Worksheet · LightMySky