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