Illustration for 🎈 What’s a Variable? – the Magic Boxes of Computer Science

What’s a Variable? – the Magic Boxes of Computer Science

Introduction

Imagine you have a Labelled Box that can hold anything you want—​a number, a word, or even a secret code. In computer programming, that box is called a Variable. Variables let computers Store, Change, and Use information, just like you might keep a snack in your lunchbox and swap it for a different treat later. Let’s explore how these magic boxes work!


1. Naming Your Box – The Variable’s Name

Every variable needs a name so the computer knows which box you’re talking about.

  • Rules:

    • Start with a letter (a‑z) or an underscore _.
    • No spaces; use Camelcase (myScore) or Snake_case (my_score).
    • Avoid words the computer already uses (called keywords).
  • Why It Matters:
    If you name two boxes the same, the computer gets confused and might use the wrong value—​just like mixing up two identical backpacks!

Example

age = 9          # The box named "age" holds the number 9
favoriteColor = "blue"   # The box "favoriteColor" holds the word blue

2. Putting Things Inside – Assigning Values

Assigning means putting a value into a variable. Think of it as putting a toy into a toy chest.

  • Cause → Effect:
    • Cause: You write score = 0.
    • Effect: The computer creates a box called score and puts the number 0 inside.

You can later Update the value: score = score + 5 (the box now holds 5).

Mini Experiment 1 – “counting Coins”

  1. Grab a piece of paper and draw three boxes labeled Coins, Bonus, and Total.
  2. Write coins = 3.
  3. Write bonus = 2.
  4. Add them: total = coins + bonus.
  5. What number is inside Total? (Answer: 5)

3. Changing over Time – Variables Are Not Fixed

Unlike a real box that stays the same size, a variable’s value can Change whenever the program tells it to.

  • Example: A video game character’s health might start at 100. When the character gets hit, you do health = health - 20. The health variable now holds 80.

  • Cause → Effect:

    • Cause: The character is hit.
    • Effect: The health variable’s value decreases, which might later cause the game to end if health reaches 0.

Mini Experiment 2 – “growing Plant”

  1. Create a variable height = 5 (centimeters).
  2. Each day the plant grows 2 cm: height = height + 2.
  3. After 3 days, what is height? (Answer: 11 cm)

4. Did You Know? 🤔

  • The word Variable comes from the Latin variabilis, meaning “changeable.”
  • Early computers didn’t have fancy names; programmers used simple letters like A, B, and C as variables.
  • In many programming languages, you can store Different Kinds of data in variables: numbers (Integers, Floats), text (Strings), and even true/false values (Booleans).

Mini Quiz & Experiment

QuestionYour Answer
1️⃣ What must a variable name start with?
2️⃣ If score = 10 and you run score = score + 7, what is the new score?
3️⃣ True or False: A variable can hold both a number And a word at the same time.

| 4️⃣ Write a tiny program (in any language) that creates a variable called cookies with value 4, then adds

| 4️⃣ Write a tiny program (in any language) that creates a variable called cookies with value 4, then adds 3 more cookies and prints the total number of cookies. | |

Example Answer (Python):

cookies = 4
cookies = cookies + 3
print(cookies)  # 7

Keep experimenting with your own numbers! 🎉

You’ve mastered the magic of variables—keep coding!

Continue the adventure

Download Surprise Button for iPad

A simple, safe way for kids to explore the internet. With one tap, they discover something new — a fun fact, a science experiment, a story, or a place in the world they never would've searched for.

Download on the App Store

Your child explores safely on Surprise Button App

🌋

How Volcanoes Form

From Magma to Mountain

Volcanoes grow where tectonic plates collide or drift apart. Heat melts rock into light, buoyant magma that rises, cools, and hardens near the surface, building the cone layer by layer.

Know exactly what to talk about tonight

Maya's Daily Discoveries - March 15 Inbox

🚀 Today's Learning Journey

🌋
How Volcanoes Form
18 min • Longest session today
🎨
Ancient Egyptian Art
15 min • Visited twice today

💬 Tonight's Conversation Starters

"Can you explain how volcanoes form?"