Coding for Kids

Photo Courtesy of Unsplash.comMy new hobby is still going strong but I do miss writing. I’m still a beginner at writing code in C#, technically, but I think I’d be more accurately tagged as an intermediate programmer. I’ve said it before: Kids need to learn coding skills. I thought it would be a good idea to try to reach the younger population but in a different way than I’ve seen. Kids don’t want to read a textbook. Well, what if there was a coding manual that taught the basic concepts through a story?

I don’t know if this plan is going to work but it’s worth an effort. It’s right up my alley, too. I’m taking a tricky piece of science and explaining it through analogy. 

Last night I wrote the first three chapters. After each chapter, I plan to create a worksheet of exercises related to the information in the chapter. At the end of a unit, I’ll put more complex worksheets that tie together the concepts from the unit. 

Coding is best learned by coding. Sure. But I’m starting here at the base level to reach kids who’ve never programmed before. I also want this to be accessible to colleagues who’ve never programmed either. Let’s be honest, it’s easy to get in deep to coding jargon but overlook the explanations. I want to fill in that gap that I’ve seen. As I’m learning to do more complex tasks, I need an explanation for what and why and how. Following the code is fine for me in most cases, but Kevin showed me something the other day that still has me confused. It’s actually what prompted this writing venture. 

So I don’t know if this is a good path to take or not, but it’s getting my typing hands back at the keyboard for storytelling. And later this year when my research class is finished with their assignments and we have some time for another challenge, maybe I’ll give this a try with them. 

But in the meantime, what do you think?
 

 

Day 1: Binary

“Moooooooom! Cody’s doing it again!” 

Mom’s voice echoed from the kitchen. “Cody, stop counting in binary numbers!”

Cody grinned and he made his way to the kitchen see his mom, with his sister, Jade, following him. “I don’t see what’s wrong with it,” he said. “We have light switches that either go on or off. That’s all I’m really doing.”

Jade shook her head. “I don’t get it, you know. We’re playing a game of Go Fish and when he asks for a seven—”

Cody interrupted, “Zero-one-one-one.”

His sister slapped his shoulder in annoyance. “There he goes again!”

“Mom,” Cody explained, “it’s how computers use numbers. They flip switches on and off—one or zero—and when they put it all together they understand everything! I think we all need to learn a bit more about it.”

Mom grabbed a pad from the counter and put it in front of Cody. Jade groaned because she knew what coming next… a lesson.

On the right side of the page, Cody wrote the number 1. To its left he wrote 2. To its left he wrote 4, then 8. “These are all powers of 2,” he said sagely. “I’m listing them from right to left because it’s just like how we read numbers. Like the number 2017… the smallest part of it, the ones digit, is on the right.”

“Yawn!” Jade said aloud.

Cody ignored the comment and pointed back to the list he had made: 8 4 2 1. “Each one of these is like a switch. If it’s on then we put a 1 under it and if it’s off then we put a zero. Using only these numbers, how could you make them add up to seven?”

Mom figured it out quickly but she waited for Jade to give it a try. Even though Cody’s sister was giving him a hard time, she knew Cody had some interesting things to say. Not that she’d ever admit that to him directly! Jade looked at the numbers that were on the page and she figured it out. “If you add 4 and 2 and 1 then you get seven.”

Cody smiled. “Right! And in this case, we don’t need the 8.” He put a zero under the 8. “We do need the 4, 2, and 1, so…” He drew a 1 under each of those numbers. “Because those numbers are switched on then the computer would add them all together and make seven. But in binary it’s written as 0111.”

“Why bother with the zero in front?” Jade asked. “We don’t say zero-eleven dollars.”

“That’s true. But we’re playing Go Fish and the cards go up to ten. So we would need to use that 8 sometimes. I’m keeping four places to be consistent.”

Jade looked at the list on the notepad: 8 4 2 1. “One-zero-one-zero. That would make it 8 plus 2 to give us ten, wouldn’t it? We wouldn’t need the 4 or 1.”

Cody beamed. “You got it! That’s binary!”

Mom was relieved that the argument was already over but she decided to push the conversation a little further. “I can see that 8 plus 4 plus 2 plus 1 equals fifteen. What if you have a larger number than that?”

“It’s base 2. That means each value here is 2 to an exponent. 20 = 1. 21 = 2. 22 = 4. 23 = 8. Then, 24 would be 16.”

Jade looked at it carefully. “That’s silly. You’re just doubling each number as you go.”

Cody agreed. “It’s kind of the same thing, yes. That’s math for you. That exponent—that number that’s up on top—tells you how many times to multiply the 2 together. So 24 is really saying 2 times 2 times 2 times 2.”

Jade frowned. “But why 2? Why not something more useful?”

“It goes back to that on/off thing I was saying before. Like a light switch, each bit can only be on or off. It’s only two possible choices. You can’t have the switch on halfway.”

“Well, you kind of can,” Jade argued.

“Not really. Sure, we can try to slide the switch up slowly, but at some point it clicks and the light goes on. There isn’t a half-on option. Either it’s on or it isn’t.”

Mom smiled, “Unless you have a dimmer switch.”

Cody nodded his head. “Yep, but that’s not the kind of switch I’m talking about here. That would make the computer process a lot more complicated!”

“It’s bad enough as it is!” Jade complained with a wink. “But really, Cody, I get it now. I guess binary really isn’t so bad after all.”

“Cool. Want to get back to our game of Go Fish?”

“Sure. But let’s play for best 011 out of 101.”

“Best 3 out of 5 it is!”

 

Day 2: For Loops

“Yo, Cody!” called Martin. “Let’s play a game of hide-and-seek!”

Cody and his friends gathered in the playground where many hiding places existed. Martin offered to be the first hunter, so he counted down from ten to one while everyone else scampered away, diving behind slides and sneaking behind trees. When Martin finished the count, he ran around the playground, seeking out his friends and tagging one. They played a few rounds until at last Cody was tagged.

“Ok,” Cody said. “My turn to count.” He turned around and shouted out loudly, “Nine!”

“Wait!” Lonna interrupted. “You have to count down from ten!”

“I am!”

“But you started at nine! That’s one tick less than anyone else is counting!”

“It’ll be ten ticks, don’t worry. I’m not trying to pull a fast one.”

Skeptical, Lonna shook her head and scanned the area for a hiding place that was closer than her originally planned spot. “We’ll see…”

Off Cody counted, “Nine! Eight! Seven!” He heard his friends sprinting away, grunting and hurling themselves to the grass. Some even tossed rocks here and there to distract Cody’s attention so he’d think someone went off to the other side.

“Six! Five! Four!” More hurried steps thundered on the ground behind him. Everyone seemed worried that he wasn’t going to count ten ticks.

“Three! Two!” He heard someone moan in frustration. It sounded like Lonna, as if she hadn’t found a spot yet. Cody laughed to himself and then finished his count.

“One! Zero! Ready or not, here I come!” Off he went, seeking out his friends, peering into the wooden pirate ship, glancing over at the monkey bars, and jogging toward the swings. He spotted Alex in a large plastic climbing tube and he dove inside and nabbed him.

Caught, Alex freed himself from the tube and called out, “I’ve been tagged! Come out, come out, let’s start again!”

As they all gathered together, Lonna turned to Cody. “I guess you really did count ten things, but why did you start at nine?”

Cody held up his hands and counted off his fingers, wiggling each one as he did so. “Zero, one, two, three, four,” on his left hand. “Five, six, seven, eight, nine,” on his right hand.

“Nobody starts at zero,” Martin said.

“Lots of people start at zero!” Cody said cheerfully. “Do you have a bank account? It started at zero didn’t it? How much food was in your belly before breakfast? None. We start at zero all the time. A car? You don’t usually climb in when it’s moving.”

“Well, I do!” Alex laughed.

“It’s an interesting point,” Lonna noted. “But your finger starts at one, not zero.”

Cody shrugged. “It depends on how you look at it. The thing is, computers default to starting at zero. It’s their beginning spot. Like the bank account thing. Start at zero and it’s all up from there.”

“You and your computer speak,” Martin smirked.

“Hey, they’re all around us. It’s a good idea for us all to learn a bit about them, I think.”

Lonna nodded. “I agree. But are you saying computers can’t count from 1 to 10?”

“Of course they can! You’d have to tell it to. But in many programming languages, they’d start counting from zero. Then they’d do something and then count up by one for as long as they’re less than ten, for instance. It gives the same result, but it’s thinking about it differently.”

Alex looked down at Cody’s hands. “So it’s kind of like you were counting your fingers from zero, then after you noted how many were up, you raised one. Then your number of visible fingers went up by one. And then you raised another until you ran out of fingers to raise up.”

“Precisely. And in computing language, that would be called a ‘for’ loop.”

Peter piped up then, “What’s a ‘for’ loop?”

Cody dropped down to his knees and grabbed a twig. He drew a set of symbols and words in the dirt:

for (int i = 0; i < 10; i++;)

{

    RaiseAnotherFinger( );

    Smile( );

}

His friends gathered closer, wondering what on Earth he had drawn and whether maybe he had hit his head or something. “Let me break it down,” Cody offered. “That word ‘for’ is a keyword. That tells the computer it’s about to go into a loop. Now, it needs a set of rules to follow and those rules are in the parentheses after ‘for’.”

“I’m counting my fingers.” He holds up his hand again with no fingers raised. “I’m starting from zero and I’m going to count in whole numbers. Right?”

“Yeah, sure,” Alex said.

“Ok, this part here, the ‘int’ says I’m using whole numbers. I’m using the letter ‘i’ because it’s sort of a default that means ‘iterator’ or counter. And I’m starting from the computer’s default of counting from zero.”

Lonna made an “ah” sound. “So then if you wanted the computer to start counting from the number 1, you could have put i = 1 instead.”

“That’s right!” Cody agreed. “But for other things, the computer is still going to start from zero, so it’s better to just get used to using zero also. Anyway, the i = 0 means I’m starting with zero fingers up. The semi-colon in C# is like a period in an English sentence. It completes a thought.”

Peter pointed to the next part: i < 10. “That looks like math. ‘i’ is less than ten.”

“Yep, you’ve got it. That part right there is the condition of the loop. As long as that statement is true, then the loop keeps going.”

“Well this part looks weird,” Martin said, pointing to the i++. “Who puts two plus signs together?”

Cody smiled. “It’s a shorthand for C#. It means to increase the counter by one. Now, the funny thing is, it doesn’t actually do this part of the line until after it finishes what’s in the loop itself.”

“Wait,” Lonna interrupted. “What if you wanted to count by 2? Would it be i+++ or i++++?”

Cody shook his head. “The syntax for it looks very different than what you’d see in math class. It’s: i = i + 2.”

“That’s impossible!” Peter argued. “No number is equal to itself plus two!”

“True and that’s the part that’s different in computers. The computer is solving the part on the right first. So it takes ‘i’ and it adds 2 to it. Then it changes the value of i to take over that answer. It’s like if you make a mistake and you erase it and write a new answer. The old one is gone and you have a new one. But in this case, it’s not a mistake. It’s how number variables work.”

Tricia, who had been watching quietly this whole time pointed to the drawing Cody had made in the ground. “What’s with these squiggly lines?”

“Those things { } are called braces, but a lot of people call them squiggly brackets. Here, they define a code block for the ‘for’ loop. The loop does everything inside of those braces and when it’s done, it goes back to the ‘for’ line and it increases the counter.”

Lonna bit her lip then said, “Ok, you start with no fingers up. You go into this loop. These instructions say to raise another finger, then smile. Then it goes up here to the i++ and it adds one. You’re in the next round of your loop and you already have one finger up. So it loops again. You raise another finger. You smile again. Then the counter goes up to two.”

“Yes,” Cody said. “And when it hits 10, that’s not less than 9 any more so the loop is done and it jumps out to go after the ending brace }. If there was more code there, it would do more stuff.”

“So the counter is counting the fingers?” Peter asked.

“Well, no. I’m just using that as an example you can follow. The counter, i, is actually counting the number of times it goes through the loop. It doesn’t actually care about fingers or smiles or anything that’s in the braces. It just wants to loop until it’s done.”

“What if you want to count down, like we’re doing before we hunt?”

Cody used the twig to draw a new loop in the dirt:

for (int count = 10; count > 0; count–;)

{

    ShoutNumber(count);

    WaitAFewSeconds(5);

}

Seek(friends);

The group looked at the new code and followed it through with Cody’s help. Alex started by saying, “Oh here it starts at ten!”

Tricia spoke next. “And I guess the count– is like the i++ but it’s counting down by one instead of counting up.”

Lonna pointed at the ShoutNumber line. “Here, you put something in the parentheses.”

“It’s called a parameter,” Cody explained. “Don’t worry about that for now, but you can probably guess what it would do.”

“I’d say that it tells you to shout out whatever number the count is at that point.”

“Correct!”

Alex focused on the command after the final brace. “Oh I see, then here you seek out the friends once the loop is done!”

Martin looked up at the sky and commented, “Speaking of done, it’s getting late. We should all get home before it’s dark.”

“Hey wait!” Lonna said excitedly, grabbing the stick from Cody and drawing something new on the ground. “Does this make sense?”

for (int day = 0; day < 7; day++;)

{

    WakeUp( );

    HaveBreakfast( );

    GoToSchool( );

    SeeFriends( );

    HaveDinner( );

    GoToSleep( );

}

“That’s great!” Cody said excitedly.

“Except for one thing,” Tricia noted, pointing at the third line under the open curly brace. “You have us coming to school seven days a week!”

 

Day 3: If Else

Dinner time with Cody was always interesting. He spent a lot of time turning basic actions into computer language, trying to explain things to his family as he went. He did this at lunchtime too with his friends. They didn’t mind too much. It was eccentric, but everyone felt like they understood Cody more and more.

Dad called Cody and Jade to the table. “It’s dinner time!” The two kids gathered around and sat down, taking in the sights. Mom and Dad had worked together to make a chicken cutlet feast with rice, corn, and salad too.

“What would you like first?” Dad asked.

Cody grinned. “If there’s butter and salt, then I’ll have corn. If there’s only butter, then I’ll have rice. If we don’t have either, then I’ll have salad.”

“Here we go,” Jade muttered.

“It’s basic decision-making!” Cody said.

Mom didn’t waste any time pulling out a notepad for their excited child. “Do tell, son.”

“Well, it’s really simple, actually. Computers can use an ‘if’ statement to test to see if something is true, like ‘is there any butter?’ If it’s true, then do something, like ‘take the rice’. And if the condition is not true—so if there isn’t any butter—then you can have the computer stop checking for things or give it an alternate task to do.”

“So if there was no butter or salt, you don’t have to have salad?” Jade asked.

“Right. Let’s start just looking at butter for rice or having salad.”

“Aw, no corn?” Dad asked with a smirk.

“I love corn! But I’ll come back to it,” Cody promised. “Here, look:”

if (butter == true)

{

    TakeRice( );

}

“This one’s simple. If there is butter, then I’m taking rice. It doesn’t matter if there’s salt, corn, or salad, or anything else. Butter? Yes? Then rice, definitely.”

Jade saw that there was indeed some butter on the table, so she grabbed the bowl of rice and served herself some. “What about your salad thing?”

“Sure, let me add that. If there isn’t any butter because Jade ate it all,” he added with a smile, “then I’ll have salad instead.”

if (butter)

{

    TakeRice( );

}

else

{

    TakeSalad( );

}

“There!”

“Wait a second!” Mom said. “You just say ‘if (butter)’. That makes no sense!”

“It’s shorthand. If the butter condition is true, then it means the ‘if’ statement is true so you don’t have to check if ‘butter’ is equal to ‘true’. You can’t always shorten things like that, though.”

Dad chuckled. “You’re shortening the shortening.”

Jade rolled her eyes. “Dad, you’re making butter jokes now?”

He winked. “You butter believe it!”

Before the silliness escalated further, Mom returned to Cody’s original decision-making example. “What about the corn?”

“Well, there are two ways to go about it. Let me show it to you the way I said it before. If there’s butter and salt then I’ll have corn. If there’s only butter, then I’ll have rice instead. Otherwise, it’s salad for me. The key here is that I’m only taking one side dish in this example.”

Dad chimed in, “So it’s going to be an unrealistic example then, because I know you’re going to end up with all three.”

Cody laughed. “Probably. But for now:”

if (butter)

{

    if (salt)

    {

        TakeCorn( );

    }

    else

    {

        TakeRice( );

    {

}

else

{

TakeSalad( );

}

Cody’s family looked over what he wrote and they talked about it as they tried to reason it out. Dad started it off. “If there is butter, then I go into this first set of braces and then we come up to a second ‘if’ statement.”

Mom added, “Then we check to see if there is any salt, and if so, then you have corn. But if there is no salt, then you go to the ‘else’ statement and take rice instead.”

Jade pondered the code next. “But I’m confused here. How does it know to go to the else with rice and not the else with salad?”

Cody pointed to the code. “See how these are indented? Those braces section off blocks of code. All the stuff that relates to having salt or not having salt is lined up under the ‘if’ statement for salt.” He took his napkin and placed it on his notes, covering up the right side. “Here I can hide all the code that relates to salt. That part is all for that ‘if’ block.”

“Oh, I see,” Jade said. “And the other ‘else’ statement happens if there was no butter.”

“Yeah. If butter is false, then it skips over the check for salt completely. It goes to the next block of code. It looks like this:”

if (Is this condition true?)

{

    Yes, it’s true, so do this;

}

else

{

    No, it wasn’t true, so do this instead;

}

Mom looked at the sets of code written so far. “Son, you said there were two ways to check for the salt and butter? What’s the other way?”

Cody turned to a new sheet and wrote quickly:

if (butter && salt)

{

    TakeCorn( );

}

else if (butter)

{

    TakeRice( );

}

else

{

    TakeSalad( );

}

“That double-ampersand && means that both butter and salt have to be true in order to take the corn. Otherwise it tests for the butter only. And if that’s not true either, then it goes to salad.”

Dad scratched his chin. “Then if there was salt but no butter, then the first condition would fail anyway because there would have to be both of them for it to be true?”

“Yep!”

Jade pointed to the command after TakeCorn. “You put the ‘if’ and the ‘else’ together here.”

“A slight shorthand, but yes. It says what it looks like… If the first thing wasn’t true, then see if this second thing is true. If it isn’t then keep going and do that other thing instead.”

“What if you leave off the last ‘else’?” Mom asked. She crossed it out and the code became:

if (butter && salt)

{

    TakeCorn( );

}

else if (butter)

{

    TakeRice( );

}

TakeSalad( );

Jade chimed in. “Then no matter what, he gets salad. But he might also get either corn or rice, but not both of those.”

“You got it!”

Dad took the notepad. “This is more accurate though:”

if (hunger > 1)

{

    TakeCorn( );

    TakeRice( );

    TakeSalad( );

}

else

{

    JustKiddingTakeAllTheFoodAnyway( );

}

Everyone had a good laugh at that, then they all started eating.

Red Jade Book Series

Red Jade Book Series

All four books of the Red Jade fantasy series are now complete and available. The entire saga spans the kingdoms of Kallisor and Hathreneir, following Dariak and his companions on their quest to end centuries of war. Gathering the shards of the Red Jade allow the companions to tap into elemental powers that give them an edge on their journey. But the jades themselves are fickle and it’s Dariak’s quest to unite them anyway.

It took roughly three years to write the four-book saga. Over the past year, each volume has been through numerous edits and updates. Cover art was created for each book to represent aspects of each story. Now they are available in print and on Kindle. If you read them, please review them on Amazon.

I can’t thank enough everyone who was involved in the entire process, including my partner, my friends and family, my beta readers, my reviewers, my editors, my cover artist, my musician, my students, my writer colleagues, and my readers.

 

Journeys in Kallisor

Book 1: Journeys in Kallisor

Meet Dariak, Gabrion, and Kitalla. A mage from Hathreneir, Dariak is determined to travel through enemy territory to gather the missing shards of the Red Jade in an effort to stop the centuries-long war. Gabrion, a farmer from Kallisor, joins the quest when his own personal mission goes awry. Kitalla, agile thief, lends her abilities to the team, including a unique dance skill that exudes magic unknown in the land. The trio journeys east through Kallisor, facing feral creatures along the way.

 

The Shattered Shards

Book 2: The Shattered Shards

After the events that culminated in book one, the team ventures west, joined by Randler, a bard of Kallisor whose dislike of magic challenges his growing relationship with Dariak. The monsters attack in droves and soldiers of the Kallisorian king’s army hunt them down. The team splits temporarily, then reconnects before heading into Hathreneir. The desert lands house new creatures and challenges. The quest for the jades brings the companions to the Hathren liege and the mages. Their biggest challenges, however, are coming to terms with their pasts.

 

The Assembly

Book 3: The Assembly

Joined by new allies, the companions fracture into four groups. From the western forest of Hathreneir to a quiet town in Kallisor, the rift between the companions must be resolved if the jades are ever to be united. Conflicts arise at every turn and Dariak must trust in his companions to handle matters while he seeks the final shard. Yet the more he learns of the pieces of the Red Jade, the less confident he is that they can even be united at all. [The format of book three is different in that it cycles among the four groups throughout the novel up through the events at the end.]

 

The Forgotten Tribe

Book 4: The Forgotten Tribe

With the team reunited and the jades gathered, Dariak’s main quest nears completion. But it isn’t as simple and lining up the jades and using their powers. Dariak must seek his father’s help to fully realize the scope of his quest, and the consequences. Kitalla, Gabrion, and other companions they’ve met along the way strive to control the chaos in Castle Hathreneir while also preparing for the culmination of the quest. At last, the questions Randler has pursued find answers as the truth of the Forgotten Tribe is revealed.

 

Red Jade Updates

Much has happened in the lands of Kallisor and Hathreneir. Dariak first ventured out on his quest to locate the shards of the Red Jade in Book 1: Journeys in Kallisor. His quest was unfinished and he and his new companions continued their journey back through Kallisor and into Dariak’s homeland of Hathreneir in Book 2: The Shattered Shards. Gathering the jades fractured his team and he had one more task left to complete before the end of Book 3: The Assembly, which is now available. And this morning, Dariak’s quest reached its conclusion as I finished edits on Book 4: The Forgotten Tribe. It will take another two weeks or so to release the final entry in the Red Jade series, but the end is nigh!

This entire journey has been phenomenal and I plan to craft out a more detailed start-to-finish description of the process to help my fellow indie authors along the way. Some areas have been easier than others and it’s kind of funny to think that writing this epic tale was the easiest part. The stories and the characters kept me well informed of what was happening to them along the way.

 

Red Jade: Book 3: The Assembly – Now Available!

Book 3: The Assembly released two weeks ago and there was so much going on here, I didn’t even write a post about it! I do apologize. To celebrate its release, I have placed the Kindle edition of Book 1: Journeys in Kallisor on sale for 99¢. Please help spread the word and tell everyone to grab a copy!

And if you have read any or all of the books, it would be a huge honor if you could please rate and review them on Amazon. Thank you so much for your support and I hope to have Book 4 in your hands before the end of June.

Quick links:

Red Jade: Book 1: Journeys in Kallisor

Red Jade: Book 2: The Shattered Shards

Red Jade: Book 3: The Assembly

Red Jade: Book 4: The Forgotten Tribe (forthcoming)