The Borehole Queue Counter

Grade 2 Scratch 3.0 Simulation first Counting Waiting Turns
Simulation lab
Tool: Scratch 3.0
Open Scratch ↗
Simulator preview

Follow instruction sequences to guide the character to the goal.

📁 Tools ▴
  • Web browser (Chrome, Edge, Firefox)
  • Internet connection
  • Scratch 3.0 online editor

🔧 Build Your Borehole Queue Counter

1 Initialize a variable called 'jerrycans_waiting' and set it to 0 at the start of each morning.
2 Program the Up Arrow key to increment the queue counter whenever a new neighbor arrives with a can.
3 Program the Down Arrow key to decrement the queue counter when a container is filled.
4 Add a defensive safety check: prevent the counter from ever dropping below zero into negative numbers!
🧩 Block plan / Starter code ▴
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 / ActionExpected Result
Press Up Arrow 3 timesCounter increments cleanly: 1, 2, then 3 waiting
Press Down Arrow onceCounter decrements from 3 down to 2
Press Down Arrow at 0Counter remains at 0; displays 'No one is waiting!'
⚑ Try a challenge

When the queue reaches 10 or more containers, display a banner that says 'High demand: Open backup solar pump!'

❓ Quick check
What happens to the 'cans_waiting' variable when a neighbor places a new water bucket in the queue line?

📖 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 / ActionExpected Result
Press Up Arrow 3 timesCounter increments cleanly: 1, 2, then 3 waiting
Press Down Arrow onceCounter decrements from 3 down to 2
Press Down Arrow at 0Counter remains at 0; displays 'No one is waiting!'

⚑ Extension Challenges & Blueprints

⚑ Extension Challenges
  • 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').

❓ Check Your Understanding

Question 1: What happens to the 'cans_waiting' variable when a neighbor places a new water bucket in the queue line?

Question 2: When a person finishes filling their can at the borehole tap, what math block updates the waiting count?

Question 3: Why does our queue counter play an alert sound when cans_waiting exceeds 8?

Question 4: What is the role of the 'Reset Day' button in our project?

Feedback appears after you check your answer.