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