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