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.
Tamagotchis, Neopets and the pets in phone games all run the same loop: time makes a number go up, you bring it down, and a picture shows how things are going.
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.
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.
The face is chosen by if hunger < 3 … else if hunger < 6 … else. What does each hunger show?
hunger
face
1
4
8
ModifyChange the code on purpose and check the result.
Milestone 1: hungry over time
The variable hunger and the feeding button A are made for you.
Inside forever, pause for 3 seconds.
Then change hunger by 1 and show it.
Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
Need a hint?
Inside forever: pause, then change hunger by 1, then show number hunger.
Another hint
3000 ms is 3 seconds.
Every few seconds, hunger goes up by 1 by itself, and shows.
This ticks by itself when your blocks do what is asked.
ModifyChange the code on purpose and check the result.
Milestone 2: a face for each feeling
Swap the number for a face. Choose your own pictures:
hunger below 3: happy.
Below 6: tired or bored.
Anything else: sad.
Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
Need a hint?
Replace show number with one if block. Click + to add else if and else.
Another hint
Ask hunger < 3 first, then hunger < 6. Anything else is very hungry.
The face shows how the pet feels: happy, tired or sad, from hunger, in one if … else if … else.
This ticks by itself when your blocks do what is asked.
MakeBuild something new using what you have learned. Expect a few tries; that is normal.
Milestone 3: tricks
The list tricks is made for you. Make a shake show one trick, picked at random. Add a trick of your own to the list.
Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
A shake makes the pet do a trick, picked at random from a list of tricks.
This ticks by itself when your blocks do what is asked.
ModifyChange the code on purpose and check the result.
Make it yours
Give your pet a life of its own. Some ideas:
It sleeps when it is dark (light level), and hunger stops going up.
B plays with it, which makes it hungrier.
A second need, such as bored, with its own number.
Try it yourselfYour edits are saved in this browser.
It takes a few seconds to load. Your work in this step is kept.
For teachers
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.
Now you can
Make a number change by itself as time passes.
Turn one number into one of several pictures with else if.
Put the ideas of the course together into a small game.