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