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.🧰 In function tip(bill), what is bill? (a) a loop (b) a screen (c) an event (d) a parameter
-
2.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Kabir")); (a) Well done, name! (b) Kabir (c) Well done, Kabir! (d) greet - 3.🧰 How do you run (call) a function called greet? (a) greet() (b) greet[] (c) #greet (d) run greet
-
4.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(3)); -
5.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(9)); -
6.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Zoya")); (a) Hi, name! (b) greet (c) Zoya (d) Hi, Zoya! -
7.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Arjun")); (a) Arjun (b) Hello, name! (c) Hello, Arjun! (d) greet - 8.🧰 What is a function? (a) a type of phone (b) a screen size (c) a named block of code (d) a list of colours
-
9.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(20, 3)); -
10.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(16)); -
11.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(5)); -
12.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Aman")); (a) Hi, name! (b) greet (c) Aman (d) Hi, Aman! -
13.🧰 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(8) + fee(4)); -
14.🧰 What does this code show?
function greet(name) {
return "Well done, " + name + "!";
}
show(greet("Meera")); (a) Well done, Meera! (b) Meera (c) Well done, name! (d) greet -
15.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(15)); -
16.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(18)); -
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(11) + fee(12)); -
18.🧰 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(6) + fee(2)); - 19.🧰 Why write a function? (a) to make code longer (b) to slow the app (c) to reuse code (d) to hide errors
-
20.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(27)); -
21.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(1)); -
22.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(4)); -
23.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(5)); -
24.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(10)); -
25.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Arjun")); (a) Welcome, name! (b) Arjun (c) Welcome, Arjun! (d) greet -
26.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(4)); -
27.🧰 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(11) + fee(5)); -
28.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(3)); -
29.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(2)); -
30.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(3)); -
31.🧰 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(1) + fee(5)); -
32.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(45, 3)); -
33.🧰 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(9) + fee(6)); -
34.🧰 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(4) + fee(1)); -
35.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(100, 2)); -
36.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(0)); -
37.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(3)); -
38.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(20, 4)); -
39.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(4)); -
40.🧰 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(5) + fee(7));
Answer key
- a parameter
- Well done, Kabir!
- greet()
- 60
- 27
- Hi, Zoya!
- Hello, Arjun!
- a named block of code
- 60
- 48
- 80
- Hi, Aman!
- 20
- Well done, Meera!
- 30
- 54
- 80
- 20
- to reuse code
- 54
- 50
- 8
- 10
- 30
- Welcome, Arjun!
- 90
- 80
- 50
- 70
- 9
- 20
- 135
- 80
- 0
- 200
- 30
- 6
- 80
- 60
- 60
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students