Fun Kids Coding Activity: Learning 5 Basic Concepts About Variables
Here’s a fun activity you can try with your kids to introduce them to what variables are.
I put this together in an attempt to see if I can get all my kids comfortable with some basic concepts in programming while keeping it fun and simple to do.
So what I came up with is a way to teach kids what variables are, in a really hands-on, interactive way that got them talking and laughing and having fun.
I would say you can try this with kids as young as 3, maybe even 2.
Here’s what you need to get started:
- A few see-through pencil holders (these will be our variables)
2. Some blocks, make sure they’re all the same shape — we used cubes (these will be the values that our variables will store)
3. A piece of paper (we’ll cut this up into smaller pieces to use as name tags for the variables)
4. A marker (to write down fun variable names on their name tags)
5. A pair of scissors (to cut up the paper)
6. And some tape (to stick the name tags on the variables)
So what’s a variable anyways?
The first thing I did was to give each child an empty pencil holder to hold in their hands as their very own variable. We learned that a variable is just a container that holds something inside.
CONCEPT #1: A variable is just a container that holds something inside.
Just like a pencil holder.
So for the remainder of the lesson we agreed to call our pencil holders variables instead.
Daddy: “So what do you each have in your hands?”
Kids: “Variables!”
Perfect. On to values.
“And what are values exactly, daddy?”
Remember when we said that a variable is something that holds something else?
Well, that something else is what we call a value.
A variable holds a value.
CONCEPT #2: A value is what a variable contains.
You see?
And my daughter immediately put a cube inside a pencil holder while my boys rushed to get their hands on some cubes faster than I could say “value assignment”.
After a short brotherly disagreement between the boys about who has more cubes, we proceeded as planned. I mean — after my daughter shared the cubes equally amongst the boys.
Daughter: “You each have 4 cubes now, ok? And? Daddy, and? And?”
Daddy: “As I was saying, a value is what a variable stores inside. So we can say that a variable has a value. For example, boys, your variables each have a value of 4 right now.”
Group nod.
Values — check.
Ok, moving on.
Variables have names too — just like us
In addition to having a value, a variable can have something else too.
It can have a name.
CONCEPT #3: Variables can have names.
Just like you and me. We all have names, including variables.
The name of a variable can be really fun. We can give our variable almost any name we want. In this case, the name of our variable is “DAD”.
So we can say we’re talking about the “DAD” variable.
Like I mentioned in the beginning, this is for pre-schoolers so they can enjoy learning about variables if they don’t read or write.
Here’s my youngest son in action:
He produced the most awesomest of all variable names in the entire universe of variables. Ever.
I didn’t tell him about syntax errors yet. I think we’ll get to that in a few more years.
More fun stuff we can do with variables: changing a variable’s value
You may have noticed that my older son’s “DAD” variable above has more cubes in it than when we first started so that means its value is no longer 1 — it’s much more.
That means we can do stuff with variables and one of the things we can do is change its value.
CONCEPT #4: The value of a variable can be changed.
So if we take cubes out or put them back in, that will change the value of the variable.
We say that “DAD is” or “DAD equals” whatever the value is stored inside.
So if there’s one cube inside, we would say that “DAD equals 1″ or if there are 3 cubes inside, we would say that “DAD equals 3″ or we could say “DAD’s value is 3″.
Even more stuff we can do with variables: changing a variable’s name
Now, as much fun as changing a variable’s value is, there’s another thing we can do with variables.
We can change their names.
CONCEPT 5: The name of a variable can also be changed.
So take another piece of paper and write another cool name on it. This time use numbers too, and the letters can be either uppercase letters or lowercase letters.
I mean big letter or small letters.
Next Steps: Data Types
Ok well, that wraps up our kids coding activity on variables. I’m sure you noticed — all our variables had the same type today: cube.
Next lesson will be all about types.
(FUTURE) CONCEPT 6: Variables can have types.
My daughter pretty much got it and she went and assembled a whole bunch of types for us to play with tomorrow.
I can already bet that my boys will fight over the lion type.
Unless the younger one goes for the crocodile.
I hope you enjoyed all the fun, we sure had a blast and we learned quite a bit.
If you try this out with your kids, I’d love to hear how your lesson went.
Until next time, stay tuned and happy coding.