Explaining if statements to kids

. 1 min read

How do you explain an if statement to an 8 year old?

I recently volunteered at a coding workshop for primary school girls. Teaching kids is a completely different game. I wondered how I was going to explain the same programming concepts my university lecturer covered a few weeks ago.

Luckily, I had some help from a Harry Potter coding wand kit. The wand is a Bluetooth device with a gyroscope, which can be used to play games in an app. The games can be customised with drag-and-drop code (similar to Scratch) or JavaScript.

Many of the girls were massive Harry Potter fans, just like me. They all wanted to wave the wand and cast Wingardium Leviosa on a feather. Many of the girls soon asked me - can we create our own spells? Of course!

We had a look through the spell list. One girl announced, "My favourite spell is Avada Kedavra". Unfortunately, the developers didn't include any of the Unforgivable Curses.

After choosing a spell (that wouldn't send us all to Azkaban), I asked the girls, what do you want to happen? Some wanted to conjure a glass of Butterbeer, others wanted beans to grow in size, or to make a car disappear. We dragged and drop the code into place.

And secretly, we were coding. If I cast Serpensortia, a serpent will be conjured. If I cast Wingardium Leviosa, all the books will levitate. If I cast Impedimenta, all the Cornish Pixies will freeze. I never said the phrase "if statement", but the girls quickly grasped the concept and they had to be dragged away from the wands by their parents!

I am an adult and a software engineer, but secretly I feel like a kid being paid to write spells all day. With a few special words, we can make incredible things happen (swish and flick optional).