App Dev Worksheet: Functions
Developer's tip (Write once, use often): function name(parameter) { …; return result; } — call it with name(value). Work out each call separately, then finish the line. Inside a function, if / return can give different results for different inputs.
NameDateTime takenScore ___ / 40
- 1.🧰 How do you run (call) a function called greet? (a) run greet (b) greet() (c) greet[] (d) #greet
- 2.🧰 What does return do in a function? (a) deletes the app (b) repeats the code (c) closes the screen (d) sends back a value
-
3.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(50, 6)); -
4.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Aman")); (a) Well done, Aman! (b) Well done, name! (c) Aman (d) greet -
5.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(10)); -
6.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 50;
}
show(fee(2) + fee(4)); -
7.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(1)); -
8.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(15, 2)); - 9.🧰 What is a function? (a) a named block of code (b) a type of phone (c) a list of colours (d) a screen size
-
10.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 20;
}
show(fee(3) + fee(4)); -
11.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(10, 2)); -
12.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(5)); -
13.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(38)); -
14.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Zoya")); (a) Hello, Zoya! (b) Hello, name! (c) greet (d) Zoya -
15.🧰 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(7) + fee(3)); -
16.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Riya")); (a) Well done, Riya! (b) greet (c) Riya (d) Well done, name! -
17.🧰 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(4) + fee(9)); -
18.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(45, 5)); -
19.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(5)); -
20.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 5)); - 21.🧰 Why write a function? (a) to reuse code (b) to hide errors (c) to make code longer (d) to slow the app
-
22.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(22)); -
23.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(30, 4)); -
24.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(15)); -
25.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 60;
}
show(fee(11) + fee(6)); -
26.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(3)); -
27.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(0)); -
28.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(1)); -
29.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(3)); -
30.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(4)); -
31.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(65, 6)); - 32.🧰 In function tip(bill), what is bill? (a) a loop (b) an event (c) a screen (d) a parameter
-
33.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(20, 2)); -
34.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 30;
}
show(fee(8) + fee(8)); -
35.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(85, 4)); -
36.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 20;
}
show(fee(10) + fee(4)); -
37.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 2)); -
38.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 30;
}
show(fee(7) + fee(5)); -
39.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 20;
}
show(fee(10) + fee(1)); -
40.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Kabir")); (a) Kabir (b) greet (c) Hi, Kabir! (d) Hi, name!
Answer key
- greet()
- sends back a value
- 300
- Well done, Aman!
- 20
- 0
- 70
- 30
- a named block of code
- 0
- 20
- 70
- 76
- Hello, Zoya!
- 40
- Well done, Riya!
- 40
- 225
- 110
- 175
- to reuse code
- 66
- 120
- 30
- 120
- 80
- 30
- 40
- 6
- 70
- 390
- a parameter
- 40
- 60
- 340
- 20
- 50
- 60
- 20
- Hi, Kabir!
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students