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