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.🔀 When does the else part run? (a) always (b) never (c) when the test is false (d) when the test is true
- 2.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) !== (c) === (d) =
-
3.🔀 What does this PIN rule show?
let pin = "9297";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 4.🔀 What does if / else let an app do? (a) draw a screen (b) save a photo (c) repeat forever (d) pick one of two actions
-
5.🔀 What number does this shop app show?
let total = 440;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 Which badge does this quiz app show?
let marks = 78;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
7.🔀 What does this battery rule show?
let battery = 91;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
8.🔀 What does this PIN rule show?
let pin = "31439";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 9.🔀 With if / else if / else, how many parts run? (a) only one (b) none (c) all of them (d) two
-
10.🔀 What does this battery rule show?
let battery = 2;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 11.🔀 What does >= mean? (a) less than (b) smaller or equal (c) greater than or equal (d) not equal
-
12.🔀 What number does this shop app show?
let total = 840;
if (total > 500) {
total = total - 50;
}
show(total); -
13.🔀 Which badge does this quiz app show?
let marks = 24;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
14.🔀 What does this battery rule show?
let battery = 42;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
15.🔀 What does this battery rule show?
let battery = 16;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
16.🔀 What number does this shop app show?
let total = 300;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 What does this PIN rule show?
let pin = "7124";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
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 = 89;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
20.🔀 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! -
21.🔀 What number does this shop app show?
let total = 340;
if (total > 500) {
total = total - 50;
}
show(total); -
22.🔀 What does this PIN rule show?
let pin = "222";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
23.🔀 What number does this shop app show?
let total = 490;
if (total > 500) {
total = total - 50;
}
show(total); -
24.🔀 What does this battery rule show?
let battery = 6;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
25.🔀 What number does this shop app show?
let total = 350;
if (total > 500) {
total = total - 50;
}
show(total); -
26.🔀 What number does this shop app show?
let total = 270;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 What number does this shop app show?
let total = 580;
if (total > 500) {
total = total - 50;
}
show(total); -
28.🔀 Which badge does this quiz app show?
let marks = 68;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
29.🔀 What number does this shop app show?
let total = 610;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 What does this PIN rule show?
let pin = "137";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
31.🔀 What does this battery rule show?
let battery = 53;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
32.🔀 What number does this shop app show?
let total = 850;
if (total > 500) {
total = total - 50;
}
show(total); -
33.🔀 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 -
34.🔀 What number does this shop app show?
let total = 630;
if (total > 500) {
total = total - 50;
}
show(total); -
35.🔀 What number does this shop app show?
let total = 690;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this PIN rule show?
let pin = "175";
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 = 40;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
38.🔀 What does this PIN rule show?
let pin = "41618";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
39.🔀 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 -
40.🔀 What does this battery rule show?
let battery = 3;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK
Answer key
- when the test is false
- ===
- PIN saved
- pick one of two actions
- 440
- Silver
- Battery OK
- Use 4 digits
- only one
- Low battery
- greater than or equal
- 790
- Bronze
- Battery OK
- Low battery
- 300
- PIN saved
- 250
- Battery OK
- Welcome!
- 340
- Use 4 digits
- 490
- Low battery
- 350
- 270
- 530
- Silver
- 560
- Use 4 digits
- Battery OK
- 800
- Welcome!
- 580
- 640
- Use 4 digits
- Bronze
- Use 4 digits
- Ask a parent
- Low battery
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students