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