Build a pet that lives on your micro:bit, using everything in this course. It gets hungry as time passes, you feed it, and its face shows how it feels.
A Tamagotchi is a number that time pushes up and you push back down, with a face to show how it's going.
What you should already know:
Pick from a list· Pick an item from a list at random, so it works however long the list grows.
Lists· Keep many values in one list, and pick one by its place, counted from 0.
Build a pocket pet. It gets hungry as time passes, A feeds it, its face shows how it feels, and a shake makes it do a trick. You already know every block it needs. You will build it in three milestones, with less help each time.
How this lesson works: Predict, Run, Investigate, Modify, Make
Predict: Read the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.
Run: Run it and compare the result with your prediction.
Investigate: Trace how each line of code connects to what you see.
Modify: Change the code on purpose and check the result.
Make: Build something new using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.
Students build a pocket pet in three milestones, using forever, events, a variable, ranges with else if, and a random pick from a list. About 55 minutes.
I can make a number change by itself as time passes.
I can turn one number into one of several pictures with else if.
I can put the ideas of the course together into a small game.
Before class
This challenge uses every lesson in the course and adds nothing new. The pet is a variable, hunger, that forever makes go up (pause, then change by 1); A brings it down (with an if so it never goes below 0); if … else if … else turns the number into a face; and a shake picks a trick from a list at random. The milestones fade the help: Milestone 1 gives nearly all the code, Milestone 2 an outline, Milestone 3 only a goal. Build it yourself first; it takes about ten minutes.
Running the lesson
Predict and Run: the pause sets the pet's speed of life. Ask what would make it get hungry faster. Count it out together: 3, 6, 9 seconds.
Investigate: three looks back: an if that guards a number, ranges, and a list with its length.
Milestone 1: if hunger never changes, the change block is outside forever.
Milestone 2: the order of the questions matters, as in The first true question wins.
Milestone 3: the trick uses pick random 0 to length − 1, from Pick from a list.
Make it yours: the sleeping pet needs an if around the change in forever.
The hard part (on purpose)
Putting it all in the right blocks. Ask which block each job belongs in: time, button, face or shake.
When students get stuck
hunger never changes. Ask: Is the change block inside forever? Fix: Drag change hunger by 1 inside forever, after the pause.
The pet is always sad, or always happy. Ask: Read the questions from the top with hunger at 4. Which is true first? Fix: Ask < 3 first, then < 6, then else.
hunger goes below 0. Ask: What does A do when hunger is already 0? Fix: Only change hunger by -1 if hunger > 0.
Stretch and support
Stretch: Add a second need, bored, with its own number, its own button and its own face rule. Which need wins when both are high?
Support: Pair students for Milestone 3: one reads the goal aloud while the other builds.
Where it leads
Course complete. Next: micro:bit: talk and play, where functions name jobs and radio connects micro:bits. With real micro:bits: keep the pet in a pocket for a lesson and see if it survives.
What each step is for
Investigate: A pet is a variable that forever changes by itself, events that change it back, and decisions that turn the number into a face.
Milestone 1: hungry over time: Time is just forever with a pause: each time round, the number changes by itself.
Milestone 2: a face for each feeling: Ranges turn one number into one of three faces: the first true question wins.
Milestone 3: tricks: Combining a list, a random place and an event shows whether a student can put the course's ideas together.