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 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 -
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 this PIN rule show?
let pin = "67671";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
4.🔀 Which badge does this quiz app show?
let marks = 31;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver - 5.🔀 When does the else part run? (a) always (b) never (c) when the test is true (d) when the test is false
-
6.🔀 What does this PIN rule show?
let pin = "348";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
7.🔀 What does this sign-up rule show?
let age = 17;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
8.🔀 What does this battery rule show?
let battery = 63;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
9.🔀 What does this battery rule show?
let battery = 35;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 10.🔀 What does >= mean? (a) less than (b) greater than or equal (c) smaller or equal (d) not equal
-
11.🔀 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) Gold (b) Bronze (c) Silver -
12.🔀 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 - 13.🔀 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
-
14.🔀 What does this battery rule show?
let battery = 94;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
15.🔀 Which badge does this quiz app show?
let marks = 90;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
16.🔀 What number does this shop app show?
let total = 420;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 What number does this shop app show?
let total = 590;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What number does this shop app show?
let total = 490;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 What does this battery rule show?
let battery = 62;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
20.🔀 What does this PIN rule show?
let pin = "27427";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
21.🔀 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! -
22.🔀 What does this PIN rule show?
let pin = "251";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
23.🔀 What number does this shop app show?
let total = 310;
if (total > 500) {
total = total - 50;
}
show(total); -
24.🔀 Which badge does this quiz app show?
let marks = 38;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
25.🔀 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 -
26.🔀 What number does this shop app show?
let total = 290;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 What number does this shop app show?
let total = 440;
if (total > 500) {
total = total - 50;
}
show(total); -
28.🔀 What does this battery rule show?
let battery = 13;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
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.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) only one (d) none
-
31.🔀 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) Gold (b) Bronze (c) Silver -
32.🔀 What number does this shop app show?
let total = 830;
if (total > 500) {
total = total - 50;
}
show(total); -
33.🔀 What number does this shop app show?
let total = 600;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 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) Bronze (b) Silver (c) Gold -
35.🔀 What does this battery rule show?
let battery = 60;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
36.🔀 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) Silver (b) Gold (c) Bronze -
37.🔀 What does this battery rule show?
let battery = 43;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
38.🔀 What does this PIN rule show?
let pin = "42695";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
39.🔀 What number does this shop app show?
let total = 240;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this PIN rule show?
let pin = "180";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits
Answer key
- Welcome!
- Ask a parent
- Use 4 digits
- Bronze
- when the test is false
- Use 4 digits
- Welcome!
- Battery OK
- Battery OK
- greater than or equal
- Bronze
- Battery OK
- pick one of two actions
- Battery OK
- Gold
- 420
- 540
- 490
- Battery OK
- Use 4 digits
- Ask a parent
- Use 4 digits
- 310
- Bronze
- Ask a parent
- 290
- 440
- Low battery
- Ask a parent
- only one
- Gold
- 780
- 550
- Silver
- Battery OK
- Silver
- Battery OK
- Use 4 digits
- 240
- Use 4 digits
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students