App Dev Worksheet: If Else Rules
Developer's tip (Test, then choose): if (test) { A } else { B }: A runs when the test is true, B when it is false. else if: check from the top; the first true test wins and the rest are skipped. >= includes the number itself; > does not. === tests “is equal to”.
NameDateTime takenScore ___ / 40
-
1.🔀 What number does this shop app show?
let total = 560;
if (total > 500) {
total = total - 50;
}
show(total); -
2.🔀 What does this sign-up rule show?
let age = 10;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! - 3.🔀 What does if / else let an app do? (a) save a photo (b) repeat forever (c) pick one of two actions (d) draw a screen
-
4.🔀 What number does this shop app show?
let total = 890;
if (total > 500) {
total = total - 50;
}
show(total); -
5.🔀 What does this PIN rule show?
let pin = "259";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
6.🔀 What number does this shop app show?
let total = 350;
if (total > 500) {
total = total - 50;
}
show(total); -
7.🔀 What does this battery rule show?
let battery = 92;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
8.🔀 What number does this shop app show?
let total = 540;
if (total > 500) {
total = total - 50;
}
show(total); -
9.🔀 What does this PIN rule show?
let pin = "886";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
10.🔀 What does this PIN rule show?
let pin = "131";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
11.🔀 What number does this shop app show?
let total = 510;
if (total > 500) {
total = total - 50;
}
show(total); - 12.🔀 When does the else part run? (a) when the test is false (b) always (c) never (d) when the test is true
- 13.🔀 What does >= mean? (a) greater than or equal (b) less than (c) smaller or equal (d) not equal
-
14.🔀 What does this battery rule show?
let battery = 41;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
15.🔀 Which badge does this quiz app show?
let marks = 79;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
16.🔀 What number does this shop app show?
let total = 600;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 What does this sign-up rule show?
let age = 15;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
18.🔀 What does this sign-up rule show?
let age = 16;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
19.🔀 Which badge does this quiz app show?
let marks = 91;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
20.🔀 Which badge does this quiz app show?
let marks = 83;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
21.🔀 What number does this shop app show?
let total = 830;
if (total > 500) {
total = total - 50;
}
show(total); -
22.🔀 What does this PIN rule show?
let pin = "359";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 23.🔀 With if / else if / else, how many parts run? (a) all of them (b) only one (c) two (d) none
-
24.🔀 What does this PIN rule show?
let pin = "546";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
25.🔀 What number does this shop app show?
let total = 440;
if (total > 500) {
total = total - 50;
}
show(total); -
26.🔀 What does this sign-up rule show?
let age = 14;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
27.🔀 What does this PIN rule show?
let pin = "6017";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
28.🔀 What does this sign-up rule show?
let age = 8;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
29.🔀 What does this sign-up rule show?
let age = 9;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
30.🔀 What does this sign-up rule show?
let age = 12;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
31.🔀 What does this PIN rule show?
let pin = "4129";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
32.🔀 What does this battery rule show?
let battery = 15;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
33.🔀 Which badge does this quiz app show?
let marks = 49;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
34.🔀 What does this PIN rule show?
let pin = "173";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
35.🔀 What number does this shop app show?
let total = 750;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this battery rule show?
let battery = 52;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
37.🔀 Which badge does this quiz app show?
let marks = 82;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
38.🔀 What does this PIN rule show?
let pin = "1808";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
39.🔀 What does this battery rule show?
let battery = 40;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 40.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) === (c) !== (d) =>
Answer key
- 510
- Ask a parent
- pick one of two actions
- 840
- Use 4 digits
- 350
- Battery OK
- 490
- Use 4 digits
- Use 4 digits
- 460
- when the test is false
- greater than or equal
- Battery OK
- Silver
- 550
- Welcome!
- Welcome!
- Gold
- Gold
- 780
- Use 4 digits
- only one
- Use 4 digits
- 440
- Welcome!
- PIN saved
- Ask a parent
- Ask a parent
- Ask a parent
- PIN saved
- Low battery
- Bronze
- Use 4 digits
- 700
- Battery OK
- Gold
- PIN saved
- Battery OK
- ===
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students