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