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.🔀 Which badge does this quiz app show?
let marks = 74;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
2.🔀 Which badge does this quiz app show?
let marks = 52;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
3.🔀 What does this battery rule show?
let battery = 14;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
4.🔀 What does this battery rule show?
let battery = 30;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
5.🔀 What number does this shop app show?
let total = 770;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 What does this sign-up rule show?
let age = 12;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
7.🔀 What does this sign-up rule show?
let age = 16;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
8.🔀 What number does this shop app show?
let total = 730;
if (total > 500) {
total = total - 50;
}
show(total); -
9.🔀 What does this PIN rule show?
let pin = "8197";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 10.🔀 What does >= mean? (a) less than (b) smaller or equal (c) greater than or equal (d) not equal
- 11.🔀 With if / else if / else, how many parts run? (a) all of them (b) none (c) two (d) only one
-
12.🔀 What number does this shop app show?
let total = 320;
if (total > 500) {
total = total - 50;
}
show(total); -
13.🔀 What number does this shop app show?
let total = 750;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 What does this PIN rule show?
let pin = "59298";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
15.🔀 What does this PIN rule show?
let pin = "2337";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 16.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) => (d) ===
-
17.🔀 What does this battery rule show?
let battery = 64;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 18.🔀 What does if / else let an app do? (a) pick one of two actions (b) draw a screen (c) save a photo (d) repeat forever
-
19.🔀 What does this PIN rule show?
let pin = "73144";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
20.🔀 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 -
21.🔀 What number does this shop app show?
let total = 500;
if (total > 500) {
total = total - 50;
}
show(total); -
22.🔀 What number does this shop app show?
let total = 370;
if (total > 500) {
total = total - 50;
}
show(total); -
23.🔀 What number does this shop app show?
let total = 260;
if (total > 500) {
total = total - 50;
}
show(total); -
24.🔀 What number does this shop app show?
let total = 800;
if (total > 500) {
total = total - 50;
}
show(total); -
25.🔀 Which badge does this quiz app show?
let marks = 69;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
26.🔀 Which badge does this quiz app show?
let marks = 30;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
27.🔀 What does this PIN rule show?
let pin = "603";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
28.🔀 What number does this shop app show?
let total = 240;
if (total > 500) {
total = total - 50;
}
show(total); -
29.🔀 What does this PIN rule show?
let pin = "40101";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
30.🔀 What number does this shop app show?
let total = 460;
if (total > 500) {
total = total - 50;
}
show(total); -
31.🔀 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! -
32.🔀 What does this PIN rule show?
let pin = "15971";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 33.🔀 When does the else part run? (a) never (b) always (c) when the test is true (d) when the test is false
-
34.🔀 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 -
35.🔀 What number does this shop app show?
let total = 760;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What number does this shop app show?
let total = 860;
if (total > 500) {
total = total - 50;
}
show(total); -
37.🔀 What does this battery rule show?
let battery = 96;
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 = "255";
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 = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this PIN rule show?
let pin = "2696";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved
Answer key
- Silver
- Silver
- Low battery
- Battery OK
- 720
- Ask a parent
- Welcome!
- 680
- PIN saved
- greater than or equal
- only one
- 320
- 700
- Use 4 digits
- PIN saved
- ===
- Battery OK
- pick one of two actions
- Use 4 digits
- Low battery
- 500
- 370
- 260
- 750
- Silver
- Bronze
- Use 4 digits
- 240
- Use 4 digits
- 460
- Ask a parent
- Use 4 digits
- when the test is false
- Battery OK
- 710
- 810
- Battery OK
- Use 4 digits
- 590
- PIN saved
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students