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