App development · lesson 17 of 24 · free

Events: on tap, do this — App development for students

Apps wait for events: things that happen, like a tap on a button, a key being typed, a timer ticking or a screen opening. Each event can have a handler — a small block of code that runs every time the event happens. In our code, button.onTap = function () { … } sets the code to run on each tap. To predict what the app shows, run the handler once for every tap and follow the values.

▶ Watch how it works

Got it? Practise ↓

Developer's tip

When this, do that — “every event (a tap, a timer, typing) runs its handler code”

  1. Event → handler → action: “on tap, do this”.
  2. The handler runs once for every tap.
  3. Counter: start + taps × step. A limit stops it growing; on = !on flips ON / OFF.

Use it for: Making buttons do something: counters, like buttons, switches and greetings.

Worked example: 👆 The user taps the button 5 times. What number does the label show now?
let stars = 3;
button.onTap = function () {
  stars = stars + 2;
  label.text = stars;
}; → 13

  1. stars starts at 3, and each tap adds 2.
  2. 5 taps: 3 + 5 × 2 = 13.

Check: 3 → 5 → 7 → 9 → 11 → 13 ✓

▶ Watch it animated

✓ Written and checked by the TalentJR team · Updated 13 Oct 2026 · How we make our lessons

✏️ Practice

Work it out in your head or on paper, then tap your answer — or type it and press Check. Stuck? Press “Show me how”.

Right: 0 · Tried: 0

🏁 Lesson 17 test

20 questions. Check each answer, then go to the next one. Get 16 or more right to pass.

🏅 Sign in with Google to earn the 👆 Event Handler Hero badge when you pass — and a certificate when you finish all 8 lessons of Part 3 · Logic and Building. You can still take the test without signing in.

🖨️ App Dev Worksheet: Events

✨ Free AI tutor

Ask the AI tutor about this lesson

Why does it work? When should you use it? Ask in English, मराठी or हिंदी.

Sign in with Google to ask Free — 20 questions a day.

👩‍🏫 App development classes — live online, request a call back

Prefer a real teacher? TalentJR teachers take live online classes anywhere in India. Tell us what you need and our team will call you with timings and fees.

Live online classesSmall groups or 1:1 with a teacher, from home, any city.
We call you backOur team asks what your child needs, then shares timings and fees.
Home tutor?We are still building our list of home tutors — ask on the call if there is one near you.
Badges, certificates & gifts A badge for every lesson you pass, a certificate for every part you finish, plus TalentJR Points for daily practice. HTML, CSS & web development Build web pages with HTML, CSS and a little JavaScript.