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