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.🔀 With if / else if / else, how many parts run? (a) all of them (b) none (c) only one (d) two
-
2.🔀 What does this PIN rule show?
let pin = "2981";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
3.🔀 Which badge does this quiz app show?
let marks = 48;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
4.🔀 What does this PIN rule show?
let pin = "3797";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
5.🔀 What does this sign-up rule show?
let age = 11;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
6.🔀 What does this PIN rule show?
let pin = "7052";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
7.🔀 What does this PIN rule show?
let pin = "6854";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 8.🔀 What does if / else let an app do? (a) repeat forever (b) save a photo (c) draw a screen (d) pick one of two actions
-
9.🔀 What does this PIN rule show?
let pin = "29293";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
10.🔀 What number does this shop app show?
let total = 500;
if (total > 500) {
total = total - 50;
}
show(total); -
11.🔀 What number does this shop app show?
let total = 230;
if (total > 500) {
total = total - 50;
}
show(total); -
12.🔀 What does this sign-up rule show?
let age = 8;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent - 13.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) => (c) === (d) !==
-
14.🔀 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 -
15.🔀 What does this sign-up rule show?
let age = 15;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
16.🔀 Which badge does this quiz app show?
let marks = 62;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
17.🔀 What does this sign-up rule show?
let age = 17;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
18.🔀 What number does this shop app show?
let total = 250;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 What does this battery rule show?
let battery = 24;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
20.🔀 Which badge does this quiz app show?
let marks = 63;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
21.🔀 What number does this shop app show?
let total = 380;
if (total > 500) {
total = total - 50;
}
show(total); - 22.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) less than (d) greater than or equal
-
23.🔀 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! -
24.🔀 What does this battery rule show?
let battery = 31;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
25.🔀 Which badge does this quiz app show?
let marks = 70;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
26.🔀 Which badge does this quiz app show?
let marks = 28;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
27.🔀 What does this battery rule show?
let battery = 55;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
28.🔀 What does this PIN rule show?
let pin = "795";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
29.🔀 What does this battery rule show?
let battery = 14;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
30.🔀 What does this PIN rule show?
let pin = "2529";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
31.🔀 What does this PIN rule show?
let pin = "114";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
32.🔀 What does this sign-up rule show?
let age = 13;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
33.🔀 What does this PIN rule show?
let pin = "89707";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
34.🔀 What does this PIN rule show?
let pin = "665";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
35.🔀 What number does this shop app show?
let total = 540;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this PIN rule show?
let pin = "33607";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
37.🔀 Which badge does this quiz app show?
let marks = 66;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
38.🔀 What number does this shop app show?
let total = 340;
if (total > 500) {
total = total - 50;
}
show(total); -
39.🔀 What does this battery rule show?
let battery = 65;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
40.🔀 What number does this shop app show?
let total = 600;
if (total > 500) {
total = total - 50;
}
show(total);
Answer key
- only one
- PIN saved
- Bronze
- PIN saved
- Ask a parent
- PIN saved
- PIN saved
- pick one of two actions
- Use 4 digits
- 500
- 230
- Ask a parent
- ===
- Ask a parent
- Welcome!
- Silver
- Welcome!
- 250
- Battery OK
- Silver
- 380
- greater than or equal
- Welcome!
- Battery OK
- Silver
- Bronze
- Battery OK
- Use 4 digits
- Low battery
- PIN saved
- Use 4 digits
- Welcome!
- Use 4 digits
- Use 4 digits
- 490
- Use 4 digits
- Silver
- 340
- Battery OK
- 550
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students