Beginner sequence · Step 2 of 3
Start here
Readiness check: Students can build the event-based pet and explain its order. Rehearse true/false with a held and released key before combining blocks.
Exact starter recipe
Use one sprite with costumes named Rest and Happy. Remove the earlier space-key event script so it cannot conflict.
when green flag clicked
forever
if <key [space] pressed?> then
switch costume to [Happy]
else
switch costume to [Rest]
end
wait (0.05) seconds
end
The sensing block reports true or false; forever checks it again.Make the simplest version work first. Then use the test and extension in this lesson.
Teacher learning resources
Preview external resources before class. The circuit reference explains the science; use this page’s specified AA kit and connection list for the build.
Scratch · Grade 5 · Guided practice
How to code this project
What you will make: Check continuously whether space is held, instead of running a timed greeting.
Core coding lesson. Save a new copy and remove the old space-key event script so two scripts do not compete.
Before you start
- Use one pet sprite with Rest and Happy costumes.
- Find Control (orange), Sensing (light blue), Looks (purple) and Events (yellow).
Opening and saving: Open the teacher-approved Scratch editor and select your sprite. The recipe is a block-by-block guide, not text to paste into Scratch. Build blocks with matching names and keep indented lines inside their enclosing blocks. Save through File → Save to your computer as an .sb3 file; no public sharing is required.
Build it one step at a time
- Add when green flag clicked from Events, then snap a forever block underneath.
- Place if–else INSIDE forever. Drag the hexagonal key space pressed? Sensing block into the hexagonal condition hole. This is not the yellow key-pressed event hat.
- Put switch costume to Happy in the if branch and switch costume to Rest in else.
- Inside forever, below the entire if–else, add wait 0.05 seconds.
- Click the green flag. Hold space for two seconds, release it for two seconds, and repeat three times.
- Point to the branch that runs on release; save your project and write why the loop is needed.
Your block recipe
when green flag clicked
forever
if <key [space] pressed?> then
switch costume to [Happy]
else
switch costume to [Rest]
wait (0.05) secondsPredict, test and record
Write your name and date on the printed page. Run every test, note the actual result, and retest after one change.
| Try this input | Expected result | Actual result / retest |
|---|---|---|
| Hold space | Happy remains visible | ________________ |
| Release space | Rest returns | ________________ |
| Hold a different key | Rest | ________________ |
If it does not work
- Checks only once? Put if–else inside forever.
- Flickers between faces? Remove the old space-event script or other scripts changing the costume.
- Cannot fit the block? Use Sensing’s hexagonal condition, not Events’ hat.
Make one change
Try another key in the sensing dropdown; update the three test cases before testing.
We changed __________. We predicted __________. Our test showed __________.
Teacher pacing: Use a 45-minute coding session: 5 minutes to predict, 10 to model a first working response, 20 for paired building, 7 for tests and 3 to save and explain. Continue in another meeting if setup or debugging takes longer; do not rush hardware checks.
Grade 5 support: Start with the working reference version, then explain each condition or state. Keep an input/expected/actual test log and change only one variable at a time.
Teacher learning resources
Preview resources before class. Follow this page’s specified reference build; another tutorial may use different hardware.
Print support: The lesson’s Print button includes this guide, recipe and test table.
For teachers
Engineering standards
This shows how the lesson connects to the national NGSS engineering standards and what student work you can collect.
3-5-ETS1-1
Define the user's need for scratch pet: is the key down? and agree on the listed success criteria and limits.
What students show: A stated user need and checked criteria; this is engineering-design practice, not a separate coding standard.3-5-ETS1-2
Compare two possible routes, pet behaviors, or switch arrangements before selecting one for the user.
What students show: Two small plans and a reason for the selected design.3-5-ETS1-3
Repeat the stated test under the same conditions, identify a failure, change one feature, and retest.
What students show: Before-and-after test entries and an explanation connecting the change to the result.Materials
- Teacher-managed computer with physical keyboard and Scratch editor
- Paper for two pet-costume sketches
- Approved folder for saving .sb3 project files
- Printable design brief
Teacher preparation
- Check readiness: Students can build the event-based pet and explain its order. Rehearse true/false with a held and released key before combining blocks.
- Prepare the event-based pet as an optional starting file.
- Show the difference between the event hat when-key-pressed and the Boolean sensing block key-pressed?.
- Prepare the printable design brief at the end of this page. Use the project picture as inspiration, not a technical diagram or a required artistic finish.
Step by step
How to teach it
Meet the beginner challenge
- Make a digital pet that stays happy while the space key is held and rests when it is released. Use keyboard sensing rather than an external sensor.
- Read the criteria together. Ask students to predict what the system should do.
Model one working action
- Use a pet with Rest and Happy costumes. Save a new copy before changing its code.
- Remove the earlier space-key event script and build the green-flag forever loop in the recipe.
- Use the exact starter recipe below. Ask a student to explain the action before demonstrating a second step.
Compare two small plans
- Sketch or arrange two possible solutions using the same materials.
- Compare each plan against the criteria; choose one and state a reason.
Build the smallest working version
- Place the key-space-pressed sensing block inside the if–else opening.
- Put Happy in the then branch and Rest in the else branch; include a short wait inside the loop.
- Start the program. Hold space for two seconds, release it, and observe both states.
Check and save
- Show one working action. Record where you stopped and what you need next.
- Save the project to the teacher-approved location using File → Save to your computer.
- Return materials and reset the workspace.
Rebuild understanding
- Read the saved plan and predict the first test.
- Reset the starting state and test the simplest action.
Test fairly
- List expected states first: space held → Happy; space released → Rest; different key held → Rest.
- Run three hold-and-release cycles, using about two seconds per state. Record the actual costume.
- Stop and restart the project; confirm it checks the current input rather than staying stuck in the previous costume.
Improve one thing
- Identify the first point where the result differed from the prediction.
- Change one instruction, code block, or mechanical feature. Repeat exactly the same test.
- If the core skill is secure, offer the extension; otherwise use the support option.
Share evidence and clean
- Let another pair try the project with your directions.
- Use the worksheet to show an original result, a change, and the new result.
- Save or label the work, then return materials.
Assessment
- The pet stays Happy while space is held and Rest while released.
- The sensing condition is checked inside a repeating loop.
- Student explains both branches and records each test case.
- Student predicts an outcome before testing.
- Test record distinguishes expected and actual results.
- Student explains why the revision helps; neat decoration and speed are not assessment criteria.
Supports & extensions
- Start with only if-space-pressed then Happy; add the else-Rest branch after discussing what release should do.
- Offer larger cards or tools, a stabilized work surface, picture cues, partner assistance, and spoken or dictated evidence.
- Extension after success: Add an on-screen button using mouse sensing as a separate version; write new test cases and avoid mixing two competing scripts.
Safety & responsible use
- Use a teacher-managed Scratch session or approved offline editor; no account or public upload is required.
- Use invented names and original pet artwork. Do not enter personal information, record classmates, or browse community content independently.
- Keep sound quiet or omit it. Use short screen breaks and share keyboard control.
No-machine alternative
Use Happy and Rest cards. One partner holds or releases a space card while another repeatedly checks it and shows the correct costume.
Printable student design brief
The challenge
Make a digital pet that stays happy while the space key is held and rests when it is released. Use keyboard sensing rather than an external sensor.
Success criteria
- The pet stays Happy while space is held and Rest while released.
- The sensing condition is checked inside a repeating loop.
- Student explains both branches and records each test case.
Constraints
- One sprite, two costumes, and the listed beginner blocks first.
- Use two 45-minute meetings; start with the working system before decoration.
- Keep test conditions consistent and change only one feature at a time.
Engineer’s notes
Printable beginner test record
Predict. Try. Improve.
Name ____________________ Partner ____________________
Our success rule: __________________________________________________
| Trial | Input / action | Expected result | First result | Result after one change |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 | ||||
| 10 |
Use three rows for the introductory tests or all ten for switch reliability. Write the held, released, or other-key state for each sensing test.
One thing we changed: ______________________________________________
Things we kept the same: ____________________________________________
Our evidence shows: _________________________________________________
