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