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