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