Oliver Learns to Code a Garden
A story that links coding with growing things, from loops to weeds.
Oliver was learning to code, and he loved it. He had made a game with a jumping cat and a spinning star. His next idea was a garden simulator, where players could plant seeds, water them, and watch them grow.
His aunt, who was a gardener, laughed when he told her. “I would like to see that,” she said. “It is not as simple as it looks.” Oliver shrugged. “It is just steps,” he said. “Plant, water, grow, repeat.” She handed him a trowel.
She led him to her vegetable patch. “If it is just steps,” she said, “write them down.” Oliver wrote: One, dig a hole. Two, drop in a seed. Three, cover with soil. Four, water. “That is a good start,” said his aunt. “Now try it.”
He followed his own instructions. But when he got to step four, he poured too much water, and the seed floated up. He tried again, and the soil was too dry. “It needs a condition,” he said. “If the soil is dry, add water. If it is wet, wait.”
“You have just invented an if-statement,” said his aunt. Oliver grinned. He realised that watering was also a loop, repeated every day until the plant grew. He sketched it on paper: repeat daily, check soil, water if dry.
Back at the computer, he wrote the code for his game, with loops, conditions and variables for sun and rain. He tested it. The virtual seed sprouted, but the plant grew sideways. There was a bug, a mistake in the code, and he could not find it.
He asked his aunt. “What happens when you find a weed?” she said. “I pull it out and look at the root.” Oliver laughed. “So debugging is like weeding.” He found the typo, a plus sign where a minus should have been.
The next version worked. His virtual sunflower grew tall and straight, and the game showed a little fanfare. He ran next door, and showed it to his aunt, and then they planted real sunflower seeds together.
Months later, a real sunflower towered over the fence, as tall as Oliver. He pointed to it, and then to his screen. “They are both gardens,” he said, “and both need care.”
✨ Key Takeaways
- Coding and gardening both rely on clear steps and careful checking.
- A bug in code is like a weed: find the root and fix it.
- Testing and repeating help us improve what we build.
💬 Questions for Discussion & Reflection
- What did Oliver learn about loops and conditions from the garden?
- How is debugging like weeding?
- What real-world task could you describe in steps, like a program?
Print a garden planting calendar →