What are Functions?
Functions are a core coding concept that help make code cleaner and more efficient. Instead of writing the same steps again and again, students can group them into a single function and reuse it.
It’s like saying “Criss Cross Applesauce”—a simple phrase that combines sitting and crossing legs. Once kids know what it means, you don’t have to explain it every time. That’s how functions work!
Where Students Use Functions in Kodable
Functions in Kodable Basics
Students first encounter functions in the Moongarden course, where they learn to spot patterns in their code. This helps students keep their code short and organized while solving the maze efficiently.
When they notice a set of commands repeating—like moving right, down, right—they can:
Create a function to store those steps
Call the function whenever they want to reuse it
This introduces an important coding principle: DRY — Don’t Repeat Yourself.
Example:
In the maze shown below, the same path pattern is used more than once. Instead of dragging each command again and again, students can group the moves into a function block and run it each time the pattern shows up.
Functions in Kodable Creator
In Kodable Creator, students take their understanding of functions to the next level. In the High Flyer course, they use functions not just to organize movement, but to control how different parts of their game work—just like real developers building reusable code!
They’ll use functions to manage:
Game sounds
Animations
Keyboard controls
Example:
In the game High Flyer, students program how the plane moves and reacts using function blocks. In the example below, you can see functions like arrowUp()
and arrowDown()
define what happens when keys are pressed, and whenHit(asteroid)
determines how the plane reacts to obstacles.
Why It Matters
Functions help programmers:
Avoid repeating the same code
Stay organized
Make edits faster and more easily