A Kid’s Guide: How to Find Common Coding Language Errors

Share on facebook
Share on twitter
Share on linkedin
Share on email

When your kids are first learning to code, no matter what language they’re writing, of course they’re going to make mistakes. This is just a natural part of learning, and essential to experience for your child to get better. However, while it may be easy to spot errors in verbal languages, in coding it’s not because they can be a little bit more complicated.

When you’re with your kids and you’re trying to help them figure out what’s wrong, obviously this is super hard work. If you don’t know coding yourself, then it can be even more complicated because whata re you even looking for?

Don’t worry, you don’t need to be put off with how complicated coding and feel, and you don’t need to feel as though you can’t help your kids be the best coders they can be. There are a few tricks and tips that can help.

In today’s guide, I’m going to talk you through some of the key ways to find common errors in your kid’s coding, helping them to identify easily where they went wrong, and what they need to improve on. Ultimately, this is going to help your kid become a successful coder!

Working on Ranges

So, your children have written out a code, but something doesn’t work. You’re getting errors pop up, the code keeps running infinitely and it’s ending with an end result like it should do, and little errors like this. One of the first things you’ll want to look for is an error known as an ‘infinite loop’.

Infinite loops are perhaps the most common error to occur because it literally just means the program or script will keep on running forever, hence the name. When a program doesn’t end, then it’s never going to finish, and this is where bugs occur.

Let’s look at this in a little more detail.

Infinite Loops When Coding with Java

Let’s say your child writes a small piece of code where they can run the program to print the numbers one through to nine. A really simple coding example of this may look like;

For(int index = 0; index < 10; index–)

{

 System.out.println(index);

}

Right off the bat, we have an error. Can you get your child to spot it? Let me give you a clue. The output of the code once running will look like this;

index = 0

Is index < 10? Yes
Print index 0
index = index – 1 index = -1
Is index < 10? Yes
Print index -1
index = index – 1 index = -2
Is index < 10? Yes
Print index -2
index = index – 1 index = -3

And so on.

Look at the end result. It says the index = -1, -2, etc. This is an infinite loop because the code will never be larger or equal to ten. It will also be in the minus figure, so it will just keep printing numbers until you turn the code off yourself because it will never reach the point of being +10, only -10.

To fix something like this in JavaScript, your original code will need to look like this;

For(int index = 0; index < 10; index++)

{

 System.out.println(index);

}

When you’re checking through your kid’s code, always look for little details like plus and minus signs being in the wrong place. The best way to check for this is to run the program and see what happens. If there’s numbers and maths involved in the code, then make sure the code is using the correct range, like in the example above!

Coding in a complex language like JavaScript can be tough because the details, like having a plus or minus sign, can make such a big difference. If you’re comfortable figuring these errors out, then keep going and you’ll pick it up in time. However, it may pay to start with a simpler coding language, like Scratch.

common coding language errors

How the Infinite Loop Error in Scratch Is Resolved

While infinite loops are mostly problematic in languages like JavaScript where you need to be super on the ball with your accuracy, you be surprised to know that they can actually be beneficial in some cases. Look at the Scratch language, for example.

There’s a feature within the Scratch language known as ‘off by one’.

For example, let’s say you have a little cartoon character onscreen that says hello to members of the family. The coding is ‘Hi FamilyName’, in which ‘FamilyName’ is replaced with text from a list of family names that you’ve written up before. You run the code and the cartoon says ‘Hi Mom’, ‘Hi Dad’, and so on.

If you have a missing family name in the list, what’s clever about Scratch is that it will automatically handle this error itself.

So say you run the program four times, but your family name list only has three entries (let’s say Mom, Dad, and Ben), the fourth time the code will run, it will omit the FamilyName because there’s no entry, and will simply say ‘Hi’!

Learning a language like Scratch is great because it omits these errors, and allows your children to focus on the fundamental aspects of coding, rather than precise details that can be taught later down the line.

Making Things a Little More Intense with Python

Python is perhaps the most complicated language out the coding languages we’ve spoken about above and would be much easier if it used the ‘off by one’ rule like Scratch does, but it doesn’t.

Let’s say you write a similar code to the Scratch, but in Python, that looks a little something like this;

family = [‘Dad’, ‘Mom’, 'Ben']
for x in range(1, 3):
print (‘Hi ‘ + family[x])

Note, you’ve got yourself an error. The ‘Dad’ entry on this code won’t print because you’re starting the range at ‘1’, rather than ‘0’, so this is where your error will occur. You’d need to write the following for the code to run properly.

family = [‘Dad’, ‘Mom’, 'Ben']
for x in range(0, 3):
print (‘Hi ‘ + family[x])

When you’re writing code, whether in Scratch, JavaScript, or Python, perhaps the most important thing you need to think about is the ranges that that coding language uses. If your child is learning multiple languages, then the ranges will differ, as we’ve spoken about already.

Scratch will automatically cover itself by omitting code that doesn’t work, Python starts it range at 0, and Javascript will use multiple ranges, depending on what you set!

So, what do you think would happen if you wrote a Python code like this;

family = [‘Dad’, ‘Mom’, 'Ben']
for x in range(0, 4):
print (‘Hi ‘ + family[x])

Well, you’d get something like this;

Hi Dad
Hi Mom
Hi Ben
Traceback (most recent call last):
 File "filename.py", line 4, in 
  print ('Hi ') + family[x]
IndexError: list index out of range

Python doesn’t use an ‘off by one’ feature, because family4 doesn’t exist.

Conclusion

When teaching your children how to code, don’t be put off with how challenging off by one errors can be, especially since the ranges will change depending on which language they’re writing in. Just take your time to learn the differences and it will become second nature in no time at all.

ABOUT THE AUTHOR

Kristin Herman is a tech project manager at Academized. She enjoys teaching children to code and helping more people get into STEM fields of learning.

Try CodeMonkey at home or at school!

free trial, credit card not required

or

for your school / district

More to explore:

codemonkey's csforall 2020 commitment

CodeMonkey’s CSforALL 2020 commitment

CodeMonkey contributes to the National Computer Science for All Movement for the 4th consecutive year.  Alongside 126 Organizations Nationwide, CodeMonkey Makes Its

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.