Lesson 4: Events

⏱ ~15 min Lesson 4 of 8 💚 Free

An event is something that happens — like pressing a button, clicking the screen, or pressing a key. In coding, you can make things happen in response to events. This is called event-driven programming, and it's how almost all apps work!

Key Concepts

What Is an Event?

An event is a trigger — something that starts an action. Clicking a button, pressing a key, moving the mouse — these are all events. When the event happens, your code responds.

Event Handlers

An event handler is the code that runs when an event happens. 'When the space bar is pressed → make the character jump' is an event handler. The event is 'space bar pressed'; the handler is 'make the character jump.'

Events in Games

Almost every game is built with events. When you press right → character moves right. When you collect a coin → score goes up. When time runs out → game over. Events make programs interactive!

🆕 Activity: Event Playground

Use the buttons to trigger different events. Each event makes something different happen on screen!

✅ Check Your Understanding

1. What is an event in coding?

2. 'When the button is clicked → play a sound' is an example of:

3. Events make programs: