App development · lesson 21 of 24 · free

Debugging: find the bug line — App development for students

A bug is a mistake that makes an app do the wrong thing, and debugging is finding and fixing it. A good way is to go line by line and compare what each line does with what it should do. In our snippets each line has a comment saying what it should do, so the bug is the line whose code does not match its comment. You can also work out what the buggy code actually shows and what it should show.

▶ Watch how it works

Got it? Practise ↓

Developer's tip

Compare with the comment — “each comment says what its line should do; the bug is where they differ”

  1. Read each line and its comment (after //): does the code do exactly that?
  2. Actual = run the lines as written. Expected = follow every comment.
  3. After the fix, test again.

Use it for: Fixing your own code and helping friends find their mistakes.

Worked example: 🐞 Each comment says what its line SHOULD do. Which line has the bug?
line 1: let stars = 36; // start at 36
line 2: stars = stars + 6; // add 6
line 3: stars = stars - 5; // take away 3
line 4: show(stars); // show it → line 3

  1. Lines 1, 2 and 4 do what their comments say.
  2. Line 3 takes away 5, but its comment says take away 3.

Check: Actual 36 + 6 − 5 = 37, expected 36 + 6 − 3 = 39 ✓

▶ Watch it animated

✏️ Practice

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

Right: 0 · Tried: 0

🏁 Lesson 21 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 🐞 Bug Squasher 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: Debugging

✨ 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 near you — online or at home

Prefer a real teacher? TalentJR teachers take live online classes anywhere in India and visit homes in selected cities. 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.
Teacher at homeA TalentJR teacher visits your home (selected cities).
At a centreClasses at a TalentJR partner centre near you, where available.
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.