Studyfin Studyfin ✨ Sign up free

Variables

Grade 4 · Coding · Free lesson

Hi there! Today we will learn about variables. They are like magic boxes that hold information in coding!

A variable is a name that holds a value. Think of it like a toy box with a label. The box stays the same, but you can change the toy inside.

geometry

We can change the data inside our variable to modify how our program works. If we change the number inside a 'speed' variable, our character moves faster or slower!

VARIABLE: "my_toy"

When we modify a variable, the computer reads the new value right away. This lets us update scores, health points, or speeds instantly in our games.

SCORE VARIABLE 10 11
✏️ Worked example

Let's change a character's speed using a variable. We want to make our hero, Pixel, walk and then run!

  1. First, we create a variable named 'pixel_speed' and set it to 5.
  2. Next, we tell Pixel to move at the speed of 'pixel_speed'. Pixel walks slowly.
  3. Then, we change the data inside 'pixel_speed' from 5 to 12.
  4. Finally, the program reads the new number. Pixel starts running fast!
math
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons