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