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