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 battery rule show?
let battery = 64;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
2.🔀 What does this sign-up rule show?
let age = 11;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
3.🔀 What number does this shop app show?
let total = 790;
if (total > 500) {
total = total - 50;
}
show(total); -
4.🔀 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! - 5.🔀 What does if / else let an app do? (a) save a photo (b) pick one of two actions (c) repeat forever (d) draw a screen
-
6.🔀 What does this PIN rule show?
let pin = "590";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 7.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) === (c) => (d) =
- 8.🔀 What does >= mean? (a) less than (b) not equal (c) smaller or equal (d) greater than or equal
-
9.🔀 What does this PIN rule show?
let pin = "80119";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
10.🔀 What does this battery rule show?
let battery = 51;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
11.🔀 What does this battery rule show?
let battery = 47;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
12.🔀 What does this PIN rule show?
let pin = "197";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
13.🔀 What does this PIN rule show?
let pin = "1854";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
14.🔀 What does this PIN rule show?
let pin = "5852";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
15.🔀 What does this PIN rule show?
let pin = "34948";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 16.🔀 With if / else if / else, how many parts run? (a) none (b) all of them (c) only one (d) two
-
17.🔀 Which badge does this quiz app show?
let marks = 42;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
18.🔀 What does this PIN rule show?
let pin = "12174";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
19.🔀 What number does this shop app show?
let total = 650;
if (total > 500) {
total = total - 50;
}
show(total); -
20.🔀 What does this battery rule show?
let battery = 20;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
21.🔀 What does this battery rule show?
let battery = 33;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
22.🔀 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 -
23.🔀 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 -
24.🔀 Which badge does this quiz app show?
let marks = 45;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
25.🔀 What does this PIN rule show?
let pin = "290";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
26.🔀 Which badge does this quiz app show?
let marks = 47;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
27.🔀 What does this PIN rule show?
let pin = "3571";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
28.🔀 What number does this shop app show?
let total = 340;
if (total > 500) {
total = total - 50;
}
show(total); -
29.🔀 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 -
30.🔀 What number does this shop app show?
let total = 850;
if (total > 500) {
total = total - 50;
}
show(total); -
31.🔀 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 -
32.🔀 What does this PIN rule show?
let pin = "72316";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
33.🔀 Which badge does this quiz app show?
let marks = 53;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
34.🔀 What does this battery rule show?
let battery = 91;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
35.🔀 Which badge does this quiz app show?
let marks = 27;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
36.🔀 Which badge does this quiz app show?
let marks = 88;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
37.🔀 What does this PIN rule show?
let pin = "913";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
38.🔀 What does this sign-up rule show?
let age = 10;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
39.🔀 What does this PIN rule show?
let pin = "31264";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
40.🔀 Which badge does this quiz app show?
let marks = 94;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver
Answer key
- Battery OK
- Ask a parent
- 740
- Welcome!
- pick one of two actions
- Use 4 digits
- ===
- greater than or equal
- Use 4 digits
- Battery OK
- Battery OK
- Use 4 digits
- PIN saved
- PIN saved
- Use 4 digits
- only one
- Bronze
- Use 4 digits
- 600
- Battery OK
- Battery OK
- Bronze
- Ask a parent
- Bronze
- Use 4 digits
- Bronze
- PIN saved
- 340
- Battery OK
- 800
- Ask a parent
- Use 4 digits
- Silver
- Battery OK
- Bronze
- Gold
- Use 4 digits
- Ask a parent
- Use 4 digits
- Gold
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students