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