App development · lesson 20 of 24 · free

Functions — App development for students

A function is a named block of code you can use again and again. It takes inputs called parameters — in function tip(bill), bill is a parameter — and gives a value back with return. To work out what a line like show(fee(2) + fee(10)) shows, run the function once for each call, write down what each call returns, and then finish the line. Functions keep app code short and tidy.

▶ Watch how it works

Got it? Practise ↓

Developer's tip

Write once, use often — “put values in, get a result back with return”

  1. function name(parameter) { …; return result; } — call it with name(value).
  2. Work out each call separately, then finish the line.
  3. Inside a function, if / return can give different results for different inputs.

Use it for: Prices, scores, greetings and any sum your app does many times.

Worked example: 🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
  if (age < 5) {
    return 0;
  }
  return 40;
}
show(fee(2) + fee(10)); → 40

  1. fee(2): 2 < 5, so it returns 0. fee(10): 10 is not under 5, so it returns 40.
  2. 0 + 40 = 40.

Check: Two 10-year-olds would pay 40 + 40 = 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 20 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 🧰 Function Builder 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: Functions

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