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