Functions for kids: Gardens by the Bay
Teach the robot to plant a tree once, then reuse it across the garden.
- Free
- No sign-up
- Ages 6–12
- Works on Chromebooks and iPads
What are functions?
A function is a set of instructions with a name. You teach the computer a new word once, like plant_tree, and from then on you can use that word anywhere. Functions stop you repeating yourself, and they make programs read like a story: "plant_tree, walk, plant_tree" is much easier to follow than a long list of steps.
In Gardens by the Bay, planting a tree always takes the same three steps: dig, plant the seed, then water it. Put those steps inside the "define" block once, then use the function block wherever a tree is needed. If you later find a mistake, you fix it in one place and every tree gets the fix.
Functions are how real software is built. Apps are made of thousands of small named pieces that call each other. The later levels combine functions with loops, the same way professional code does, and the "Show me the Python" button shows you the def keyword that Python uses to define a function.
The levels
- Level 1 First Seed Planting a tree takes three steps, in order: dig, plant, water. Grow one tree.
- Level 2 Teach plant_tree Three trees to plant. Put dig, plant, water inside the "define plant_tree" block, then use "plant_tree" three times.
- Level 3 Functions in Loops Five soil patches in a row. Your function works inside a loop too!
- Level 4 Row by Row This time the function plants a whole row and walks back to the start. Then the main program just repeats it.
- Level 5 Supertree Steps The soil patches go down like stairs. Find the pattern and use your function.
- Level 6 Flower Dome Path Plant along the top path, walk round the hedge, then plant back along the bottom.
- Secret bonus Supertree Grove Get three stars on all six levels to unlock it.
Teachers: every level has its own address, like dotcodecampus.com/maze/gardens/3. Press Copy link on a level, then paste it into your
slides or class chat, or open it on the projector. The Gardens by the Bay lesson plan has the answer keys.
Using the Robot Maze in class?
Make a class: students join with a code and a nickname, and you see everyone's stars, and who is stuck, as they play. 14 days free, then S$2.99 a month or S$29 a year. Every world also has a free 45-minute lesson plan with answer keys.
