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