The Borehole Queue Counter
Follow instruction sequences to guide the character to the goal.
- Web browser (Chrome, Edge, Firefox)
- Internet connection
- Scratch 3.0 online editor
🔧 Build Your Borehole Queue Counter
when [green flag] clicked
set [jerrycans_waiting v] to [0]
say [Solar Borehole Tap Ready. Queue: 0]
when [up arrow v] key pressed
change [jerrycans_waiting v] by (1)
play sound [Pop v]
say (join [New arrival! Waiting: ] (jerrycans_waiting))
when [down arrow v] key pressed
if <(jerrycans_waiting) > [0]> then
change [jerrycans_waiting v] by (-1)
say (join [Jerrycan filled! Remaining: ] (jerrycans_waiting))
else
say [No one is waiting! Tap is idle.]
end
Checking 'if waiting > 0' ensures queue numbers never drop into negative numbers.
⚗️ Test your model
| Test Condition / Action | Expected Result |
|---|---|
| Press Up Arrow 3 times | Counter increments cleanly: 1, 2, then 3 waiting |
| Press Down Arrow once | Counter decrements from 3 down to 2 |
| Press Down Arrow at 0 | Counter remains at 0; displays 'No one is waiting!' |
When the queue reaches 10 or more containers, display a banner that says 'High demand: Open backup solar pump!'
📖 Our Story & Concepts
In many Nigerian communities, solar boreholes provide clean drinking water. When dozens of neighbors arrive in the morning with yellow jerrycans, keeping an orderly queue prevents misunderstandings and ensures everyone gets water fairly.
Digital counters track people, cars, and packages all around the world. In this project, you learn how to increment (add 1) and decrement (subtract 1) variables. Crucially, you learn defensive programming: in real life, you cannot have negative five jerrycans waiting, so your code protects the counter from bad data!
</> Full Annotated Code Walkthrough
// Complete Borehole Queue Management Script
when [green flag] clicked
set [jerrycans_waiting v] to [0]
set [total_served_today v] to [0]
say [Borehole Tap Station Active.]
when [up arrow v] key pressed
change [jerrycans_waiting v] by (1)
play sound [Pop v]
say (join [Queue count: ] (jerrycans_waiting))
if <(jerrycans_waiting) >= [10]> then
say [ALERT: Queue is long! Please pump faster.]
end
when [down arrow v] key pressed
if <(jerrycans_waiting) > [0]> then
change [jerrycans_waiting v] by (-1)
change [total_served_today v] by (1)
say (join [Filled! Total served today: ] (total_served_today))
else
say [Tap idle: zero jerrycans in line.]
end
Checking 'if waiting > 0' ensures queue numbers never drop into negative numbers.
▷ Expected Results & Troubleshooting
| Test Condition / Action | Expected Result |
|---|---|
| Press Up Arrow 3 times | Counter increments cleanly: 1, 2, then 3 waiting |
| Press Down Arrow once | Counter decrements from 3 down to 2 |
| Press Down Arrow at 0 | Counter remains at 0; displays 'No one is waiting!' |
⚑ Extension Challenges & Blueprints
- Level 1: Add a daily total counter that tracks how many jerrycans have been filled all day.
- Level 2: Display a water icon that changes size depending on whether the queue is short or long.
- Level 3: Add a reset button with a confirmation question ('Reset daily count? Yes/No').