🔢 Variables
What You'll Learn
- Understand what a variable is in programming
- Use Set Step blocks to store the turtle’s movement distance
- See how changing one variable changes your whole program
What Is a Variable?
A variable is a named box that stores a value. Your program can read the value, change it, and use it later. Instead of typing the same number over and over, you store it in a variable — then changing the variable changes it everywhere at once.
Think of a variable like a sticky note on your fridge. The note says step = 60. Every time the turtle needs to know how far to move, it reads the sticky note. You can erase the note and write a new number — and now the turtle uses the new number everywhere!
Variables are one of the most important ideas in all of programming. Every language — Python, JavaScript, Scratch, Java — uses them.
The Step Variable 🔢
In our turtle engine, every turtle has a step variable. It controls how far the turtle moves when you use Move Forward or Move Backward without typing a specific number.
Three blocks let you change the step variable:
- 🔢 Set Step = Small (20) — tiny, careful steps
- 🔢 Set Step = Medium (60) — the default, normal steps
- 🔢 Set Step = Large (100) — giant leaps
Once you set the step, every Move Forward after that uses your new value — until you change it again.
In real programs, variables let you write code that works for any input, not just one fixed value. A game character’s speed, a score, a name — all stored in variables. You change one line to change the whole behavior.
Changing Step Mid-Program
The most powerful thing about variables is that you can change them while the program runs. Try this:
- Set Step = Small
- Move Forward (uses 20)
- Set Step = Large
- Move Forward (uses 100)
- Turn Right
- Set Step = Medium
- Move Forward (uses 60)
Each move covers a different distance — because the variable was different each time. The Move Forward block did not change, but its behavior did!
Build a staircase pattern by changing the step variable between moves. Here is one way to start:
- Set Step = Small → Move Forward → Turn Right
- Set Step = Medium → Move Forward → Turn Right
- Set Step = Large → Move Forward → Turn Right
- Set Repeat to 3 and Run — a growing spiral!
Bonus challenge: Can you use all three step sizes with a color change between each to draw a colorful staircase?
What is a variable?
If you use Set Step = Small and then click Move Forward, how far does the turtle go?
Why are variables useful?
Course Complete!
You have mastered all 10 Block Coding lessons: algorithms, sequences, movement, drawing, loops, patterns, debugging, conditionals, and variables. These are the same ideas every professional programmer uses. You are ready for the next track!
Explore More Courses →