Lesson 10 of 10

🔢 Variables

🎯 Grades 3–5 ⏱ ~25 minutes 💚 Intermediate

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.

💡
Real-Life Analogy

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.

💡
Why This Matters

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:

  1. Set Step = Small
  2. Move Forward (uses 20)
  3. Set Step = Large
  4. Move Forward (uses 100)
  5. Turn Right
  6. Set Step = Medium
  7. 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!

🔢 Step It Up!

Build a staircase pattern by changing the step variable between moves. Here is one way to start:

  1. Set Step = Small → Move Forward → Turn Right
  2. Set Step = Medium → Move Forward → Turn Right
  3. Set Step = Large → Move Forward → Turn Right
  4. 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?

Quick Check

What is a variable?

AA type of loop that repeats forever
BA named box that stores a value your program can use and change
CA block that draws a shape

If you use Set Step = Small and then click Move Forward, how far does the turtle go?

A60 pixels (the default)
B20 pixels
C100 pixels

Why are variables useful?

AThey make programs shorter by removing loops
BYou can change one value and it affects the whole program
CThey only work in Scratch, not in real programming
🎉

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 →