App development · lesson 18 of 24 · free

if / else: app rules — App development for students

Apps follow rules: show Low battery when the battery is under 20, ask a parent when the user is under 13, give a Gold badge for 80 marks or more. In code, if (test) { … } else { … } checks the test with the real value and runs only one of the two parts. With else if, the tests are checked from the top, and the first true one wins. Always check the edge value too: is 80 itself a Gold?

▶ Watch how it works

Got it? Practise ↓

Developer's tip

Test, then choose — “if the test is true run the if part, otherwise the else part”

  1. if (test) { A } else { B }: A runs when the test is true, B when it is false.
  2. else if: check from the top; the first true test wins and the rest are skipped.
  3. >= includes the number itself; > does not. === tests “is equal to”.

Use it for: Age checks, scores and badges, discounts, battery and PIN rules in your apps.

Worked example: 🔀 Which badge does this quiz app show?
let marks = 24;
if (marks >= 80) {
  show("Gold");
} else if (marks >= 50) {
  show("Silver");
} else {
  show("Bronze");
} → Bronze

  1. Is 24 >= 80? No. Is 24 >= 50? No.
  2. Both tests are false, so the else part runs.

Check: With 80 marks it would be Gold, since 80 >= 80 ✓

▶ 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 18 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 🚦 App Rule Maker 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: If Else Rules

✨ 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.