Family edition
App Maker: But If
Your child takes an app that counts taps and teaches it to notice when the count reaches 20.
What you need
- A computer or Chromebook with a current browser, and a mouse or trackpad.
- The lesson link: mytekdev.com/try/appmaker?lesson=but-if&ref=fam-appmaker-3. No account, no email and nothing to install.
Before you start: try it once yourself
Open mytekdev.com/try/appmaker?lesson=but-if&ref=fam-appmaker-3. A short guide opens over the app. The phone shows a 0, the words Get to 20, a round Tap button, Back to zero and Wins: 0. Two cards sit under the phone: Tap! and You did it.
- Nothing at 20. Press Try it and tap past 20. The number keeps climbing. Press Keep designing.
- Read the button. Click the Tap button. The panel reads: When tapped, first: add 1 to taps, play Pop. Then go to: Nowhere. Under But if there is one line: + Go somewhere else when a number gets there.
- Add the rule. Click that line. A sentence appears with three things to set. Make it read: taps, is at least, 20, go to, You did it.
- Try it. Press Try it and tap to 20. On the twentieth tap the yellow You did it screen appears. Again sets taps to 0, adds 1 to wins and goes back.
- The code. Press Keep designing, click the Tap button and press See the code. The highlighted lines include: numbers.taps = numbers.taps + 1; and if (numbers.taps >= 20) return 's2';
- The trace. Tap 18: the number becomes 18, the condition is false, the app stays. Tap 19: 19, false, stays. Tap 20: 20, true, goes to You did it.
The ideas, in plain words
A conditional is a check with two outcomes. The thing checked is a condition, and it is true or false. In App Maker a button's But if is its conditional: a number, a comparison (is at least, is at most, is exactly), a value, and a screen to go to when the condition is true. When it is false the button does what Then go to says.
Order matters. When a button is tapped its steps run first, from the top. Then the But if is checked. Then the button goes where it goes. So on the twentieth tap the app adds 1, making 20, and then asks whether taps is at least 20. If the check came first, the app would need twenty-one taps.
Is at least is the safe comparison for a counter. Is exactly works here too, because the number goes up by one and cannot skip 20. Change the step to add 3 and is exactly 20 never comes true: 18, then 21. Is at most 20 is true on the very first tap.
In the code, the rule is one line inside the button's function: if (numbers.taps >= 20) return 's2';. The name s2 is the app's own name for the second screen. The symbol >= means is at least.
App Maker is not a text programming language. Children build each rule as a sentence and the app writes the code, which they can read and cannot edit. It has no loops and no lists, a button holds one But if, and numbers are the only kind of data an app remembers. What it does have is the real thing in small: events, a sequence of steps, variables and a conditional, in an app that runs.
Do it together
- Open mytekdev.com/try/appmaker?lesson=but-if&ref=fam-appmaker-3 together. A short guide opens over the app. Press Try it and tap past 20.
You'll know it worked when: The number keeps going up. Nothing happens at 20.
- Press Keep designing. Click the Tap button on the phone and read its panel aloud.
You'll know it worked when: When tapped, first: add 1 to taps, play Pop. Then go to: Nowhere.
- Scroll down to But if and click + Go somewhere else when a number gets there. Make it read: taps is at least 20, go to You did it.
If you get stuck: There are three boxes to set: the number, the mark, and the screen.
You'll know it worked when: The sentence in the panel reads: taps, is at least, 20, go to, You did it.
- Press Try it and tap to 20.
You'll know it worked when: On the twentieth tap a yellow screen says 20 taps!
- Ask: how many times did the app check whether the number was at least 20?
You'll know it worked when: Twenty times. It checks after every tap. The answer was no nineteen times.
Talk about it
Ask these while you work together. A child who has understood it can answer them without help:
- How many times does the app check the number on the way to 20?
- On the twentieth tap, what happens first: the add, or the check?
- What does the button do when the condition is false?
- What would is at most 20 do on the first tap?
- Which line of the code is your rule?
For younger and older kids
Younger: For a younger child, set the mark to 5 and count the taps together.
Older: For a teenager, click the Tap button, press See the code, and find the line with 20 in it.
Keep going
- Change is at least to is at most, with 20. What happens on the first tap, and why?
- Change it to is exactly 20, then press Back to zero at 19. Does the rule still work? When would is exactly go wrong?
- On the You did it screen, the Again button adds 1 to wins. Add a But if to it that goes to a new screen at 3 wins.
Bring it into other subjects
- Math: write each comparison with a symbol. Is at least is ≥, is at most is ≤, is exactly is =. Which numbers make each one true for 20?
- Science: a thermostat is a conditional. Write its rule as a But if sentence.
- English: find a sentence in a set of game rules that starts with "if". What is the condition, and what are the two outcomes?
- At home: find one thing in the house that checks a number and acts on it.
For your records
Ready to copy into an hour log, a portfolio or a transcript.
| Lesson | App Maker: But If |
|---|---|
| Subjects | Computer science, Technology |
| Time | 45 minutes |
| What we did | Added a conditional to a small app so that a button goes to a different screen when a variable reaches a value, and traced the program tap by tap. |
| Skills practiced | Conditionals; Tracing a program; Comparisons |
App Maker: But If
Activity sheet (optional)
Name: ______________________________ Date: ______________
Open the app: scan the QR code, or go to mytekdev.com/try/appmaker?lesson=but-if
Essential question: How can the same tap do one thing most of the time and something different once?
Warm-up: A vending machine does nothing, then one more coin and the snack drops. What was it checking? ____________________
- Vocabulary. Conditional, condition, true and false, trace, sequence: write each in your own words.
- My rule. But if ____________ is ____________ ______, go to ____________.
- The trace table. For the taps that make the number 18, 19 and 20, write: the number after the step, whether the condition is true or false, and where the app goes.
- Change it. Try is exactly 20, then is at most 20. Write what each one does.
1. On the twentieth tap, does the app check before it adds 1 or after? How do you know?
2. Which comparison is the safest for this app: is at least, is exactly, or is at most? Why?
Quick check
Name: ______________________________
1. A conditional is (A) a number an app remembers (B) a check that makes a program do one of two things (C) a button that plays a sound
2. A button adds 1 to taps, then checks: but if taps is at least 5, go to Win. The number is 4. The button is tapped once. The app (A) stays, because 4 is less than 5 (B) goes to Win, because the add happens first and makes 5 (C) goes to Win twice
3. Write a But if sentence for a game that ends when lives reaches 0.
Answers
| Question | Answer | Why |
|---|---|---|
| 1 | B | The condition is true or false, and the program does one thing or the other. |
| 2 | B | Steps run first, then the check. 4 plus 1 is 5, and 5 is at least 5. |
| 3 | But if lives is at most 0, go to Game over | Accept is exactly 0. Is at most is safer if a step can take away more than 1. |
If your state or umbrella school asks, this lesson covers CSTA 2017 1B-AP-10, CSTA 2017 2-AP-17.