My 5 Year Old Daughter Learns to Program

Teaching and Sharing

Last night I had one of my finest moments as a parent. Being a life-long programmer I always wondered how I could share my passion for building software with my child. Now that Anna is five and a half, and has learned so much at her marvelous Montissory school, I figured it was time to see what piques her interest. Thankfully she soaked up our first lesson eagerly wanting more!

Math

I started with math. Computers do numbers all day and all night. My daughter had learned four-digit addition over the past year and I figured that was the association she needed to pull her in. I wanted Anna to reach that “ah-ha!” moment as we connected-the-dots. I built a simple two file project showing the very fundamentals of writing some code. All I needed is an index.html and a .js file included and run on page load/refresh. It’s simple and effective.

GitHub Project

All the source is in a GitHub project and I encourage you to read and use it in any way you like for your own personal pursuits.

https://github.com/KDawg/AnnaTeaching

If you’re a corporation interested in this just throw a bucket of money my way and we’ll figure out how to make it work 😉

The Programmer’s Editor

I started off teaching Anna what an editor is. We use JetBrains PHPStorm at our house. Far more than just coding I realized Anna learned:

  • What the cursor is and how to move it around the file using the arrow keys
  • How to backspace over numbers erasing them
  • How to move the mouse pointer up to the toolbar pressing the little blue square (will I ever bother telling her that icon is a floppy disk?)
  • Bugs exist (you mean there’s a bug in the computer? – ah I love that innocent joker) and a proper editor underlines them helping us code past mistakes
  • That this editor app is where we write programs, and a program is how we talk to the computer

The Web Page Browser

Anna learned about the Google Chrome web browser and again, her education was fundamental and more than just programming:

  • How to navigate between the two apps
  • How to press the circular arrow to reload
  • That this is where the computer reads the program acting out what it says to do like a play or recital
  • She eventually got confident enough to figure out how to press-and-hold to drag-and-drop the vertical scroll bar. My brain was frozen on how to teach that in words, but she just got in there and sorted it out. Fantastic!

Pro-Tip: Slow Down the Mouse Pointer

Go to your system setting and slow down the mouse pointer. Way down. Almost to the point that it’s excruciatingly slow for you, and then move it another notch lower. A kiddo this age is still dialing in their eye-hand coordination and this helps them manage the mouse and pointer without frustration.

Source Code

Such a simple little program but ripe with ideas and fundamentals excited and delighted my daughter.

(function() { var i; var value; var start = 1; var end = 10; var by= 1; value = start; for (i = start; i <= end; i += by) { document.write(value + '
'); value = value + by; } }) ();

I taught her how to change the starting number, then the ending number, and eventually the add-by number. Each time she ran our program the for loop spun through the ranges, accumulating the sum, and printed out the result.

The first few times I walked her through it, and with little prompting on editing, she took it from there experimenting and testing as her desire swept along. Seeing her curioustiy activated is the best thing ever for me as her father. Here’s some of her test runs:

  • I started with 1 to 5 by 1
  • Then I suggested changing 1 to 10 by 1
  • Prompting her, “What’s next?”, Anna tried 10 to 13 by 1
  • Then she did 20 to 20 by 1, “What will happen daddy?” I replied “Try it, you won’t hurt the computer.” Of course she said, “Only hurt the computer if you drop it.” Too true babe!
  • Then she did 20 to 40 clapping and hopping in the chair. “A giant number daddy!”

An Interlude

At that point she stopped working and ran off for a few minutes. I took notes on the effort so far thinking this exercise is already winning. Anna really dug in there, had great confidence, and sorted out what’s up with this crazy business that I love so much.

Snacks! How Does She Know?

Anna came back with the serving tray. “I made snacks for us daddy.” How my heart soared. How in the world does she know coders love snacking while they work? Is it instinct? Has she seen me do that a dozen times before? Is it genetic instruction passed on by DNA encoding?

I must admit her choice in snacks was far more healthy than mine at her age. A bowl of cherry tomatoes for her and half a banana for me. Paired with our own bottles of Mineral Water as well. God I love her.

Back to Business

Snack time over Anna continued and I wanted to show the final variable, “by”.

  • I suggested 20 to 100 by 5
  • She initiated 0 to 100 by 10
  • Anna’s eye lit up and her final test run was 0 to 1000000 by 10. “Can I try to one zillion next?”

Summary

In the end Anna was completely elated by the experience and I was so satisfied sharing what I know and enjoy with my daughter. I realize it’s the first of many sessions if I can only figure out what to present next. I don’t want to overwhelm her but there’s much to share.

I can tell Anna is proud of her accomplishment. As we wrapped up she cheered loudly confidentially proclaiming, “When I go to school I’m going to tell my teacher and my momma that I can program the computer.”

Share on X (Twitter) ➚

Ending logo Mark for this article
Intro to GenAI course advert