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.
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!
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.
✏️ Worked example
Let's change a character's speed using a variable. We want to make our hero, Pixel, walk and then run!
First, we create a variable named 'pixel_speed' and set it to 5.
Next, we tell Pixel to move at the speed of 'pixel_speed'. Pixel walks slowly.
Then, we change the data inside 'pixel_speed' from 5 to 12.
Finally, the program reads the new number. Pixel starts running fast!
Want the full interactive lesson — quiz, animations, and Finn cheering them on?