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 double(n) {
return n * 2;
}
show(double(9)); -
2.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(4) + points(0)); -
3.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Aman")); (a) greet (b) Welcome, name! (c) Aman (d) Welcome, Aman! - 4.🧰 What does return do in a function? (a) repeats the code (b) closes the screen (c) deletes the app (d) sends back a value
-
5.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(4)); -
6.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(3) + points(3)); -
7.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(1)); -
8.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(70, 4)); - 9.🧰 What is a function? (a) a screen size (b) a type of phone (c) a list of colours (d) a named block of code
-
10.🧰 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(4) + fee(8)); -
11.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(5)); -
12.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(6)); -
13.🧰 A museum app works out the entry fee. What number does this code show?
function fee(age) {
if (age < 5) {
return 0;
}
return 60;
}
show(fee(10) + fee(12)); -
14.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(18)); -
15.🧰 What does this code show?
function greet(name) {
return "Hello, " + name + "!";
}
show(greet("Aman")); (a) Hello, Aman! (b) greet (c) Hello, name! (d) Aman -
16.🧰 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(11) + fee(3)); -
17.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(20, 6)); -
18.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(11)); -
19.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(5) + points(0)); -
20.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(4)); - 21.🧰 In function tip(bill), what is bill? (a) a screen (b) an event (c) a parameter (d) a loop
-
22.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Kabir")); (a) Kabir (b) greet (c) Welcome, Kabir! (d) Welcome, name! -
23.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(35)); -
24.🧰 What does this code show?
function greet(name) {
return "Hi, " + name + "!";
}
show(greet("Riya")); (a) Hi, name! (b) greet (c) Riya (d) Hi, Riya! - 25.🧰 How do you run (call) a function called greet? (a) greet[] (b) greet() (c) #greet (d) run greet
-
26.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(10, 6)); -
27.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(32)); -
28.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(65, 5)); -
29.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(5)); -
30.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(3)); -
31.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(25, 2)); -
32.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(1) + points(1)); -
33.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(3)); -
34.🧰 What number does this code show?
function double(n) {
return n * 2;
}
show(double(26)); -
35.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(10, 2)); -
36.🧰 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(12) + fee(12)); -
37.🧰 What number does this code show?
function total(price, qty) {
return price * qty;
}
show(total(35, 5)); -
38.🧰 What number does this code show?
function triple(n) {
return n * 3;
}
show(triple(10)); -
39.🧰 What number does this code show?
function points(stars) {
return stars * 10 + 5;
}
show(points(2) + points(5)); -
40.🧰 What does this code show?
function greet(name) {
return "Welcome, " + name + "!";
}
show(greet("Meera")); (a) Welcome, Meera! (b) Welcome, name! (c) greet (d) Meera
Answer key
- 18
- 50
- Welcome, Aman!
- sends back a value
- 60
- 70
- 70
- 280
- a named block of code
- 20
- 70
- 12
- 120
- 54
- Hello, Aman!
- 20
- 120
- 33
- 60
- 8
- a parameter
- Welcome, Kabir!
- 105
- Hi, Riya!
- greet()
- 60
- 96
- 325
- 15
- 50
- 50
- 30
- 60
- 52
- 20
- 100
- 175
- 30
- 80
- Welcome, Meera!
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students