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