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