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