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