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 number does this shop app show?
let total = 730;
if (total > 500) {
total = total - 50;
}
show(total); -
2.🔀 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) Gold (b) Bronze (c) Silver -
3.🔀 What does this sign-up rule show?
let age = 13;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
4.🔀 What number does this shop app show?
let total = 450;
if (total > 500) {
total = total - 50;
}
show(total); - 5.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) greater than or equal (d) less than
-
6.🔀 What does this battery rule show?
let battery = 93;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
7.🔀 What does this PIN rule show?
let pin = "135";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
8.🔀 What does this battery rule show?
let battery = 35;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
9.🔀 Which badge does this quiz app show?
let marks = 26;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
10.🔀 What does this battery rule show?
let battery = 20;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
11.🔀 What does this battery rule show?
let battery = 41;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
12.🔀 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! - 13.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) === (c) => (d) !==
-
14.🔀 What does this battery rule show?
let battery = 5;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
15.🔀 What does this battery rule show?
let battery = 80;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
16.🔀 What does this PIN rule show?
let pin = "5220";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
17.🔀 What number does this shop app show?
let total = 210;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What number does this shop app show?
let total = 350;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 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) Silver (b) Bronze (c) Gold -
20.🔀 What does this battery rule show?
let battery = 99;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
21.🔀 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 -
22.🔀 What does this battery rule show?
let battery = 12;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
23.🔀 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! -
24.🔀 What does this battery rule show?
let battery = 71;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
25.🔀 What does this sign-up rule show?
let age = 12;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
26.🔀 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 -
27.🔀 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) Gold (b) Silver (c) Bronze -
28.🔀 What does this battery rule show?
let battery = 70;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 29.🔀 What does if / else let an app do? (a) draw a screen (b) repeat forever (c) save a photo (d) pick one of two actions
-
30.🔀 What does this PIN rule show?
let pin = "2083";
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 = 67;
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 = 670;
if (total > 500) {
total = total - 50;
}
show(total); - 33.🔀 When does the else part run? (a) always (b) when the test is false (c) when the test is true (d) never
-
34.🔀 What number does this shop app show?
let total = 760;
if (total > 500) {
total = total - 50;
}
show(total); -
35.🔀 What number does this shop app show?
let total = 610;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What number does this shop app show?
let total = 580;
if (total > 500) {
total = total - 50;
}
show(total); - 37.🔀 With if / else if / else, how many parts run? (a) only one (b) two (c) none (d) all of them
-
38.🔀 What number does this shop app show?
let total = 430;
if (total > 500) {
total = total - 50;
}
show(total); -
39.🔀 What number does this shop app show?
let total = 310;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this PIN rule show?
let pin = "337";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits
Answer key
- 680
- Silver
- Welcome!
- 450
- greater than or equal
- Battery OK
- Use 4 digits
- Battery OK
- Bronze
- Battery OK
- Battery OK
- Ask a parent
- ===
- Low battery
- Battery OK
- PIN saved
- 210
- 350
- Silver
- Battery OK
- Silver
- Low battery
- Welcome!
- Battery OK
- Ask a parent
- Welcome!
- Bronze
- Battery OK
- pick one of two actions
- PIN saved
- Battery OK
- 620
- when the test is false
- 710
- 560
- 530
- only one
- 430
- 310
- Use 4 digits
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students