So you want to learn to code?
11 FUN Things to Learn When Starting Out Coding
- Gregory Beutler, Director Techscool.org
MIT’s Scratch programming language is a great tool to introduce your students from grades 4–10 to programming. It is intuitive and provides immediate feedback to any code created. This helps tremendously with the learning curve, especially as budding coders.
Scratch is available for free and runs in your browser, so it runs fine on PCs or Macs or Chromebooks. Just point your browser at https://scratch.mit.edu/ and click on the ‘create’ button.
Coding is essentially a language to have a computer help solve a particular problem. The problem is solved by breaking it down into events and sequences and applying conditionals to make decisions as how to proceed next. This is fun problem solving!
1 Events and Sequences will be discussed first in this Scratch project to help illustrate the key concepts in coding.
https://scratch.mit.edu/projects/78102596/
A you can see the project starts with the question “ Are you Batman?”
This is a sprite(character in Scratch parlance) and is animated, most of the circles are sprites on the project and several off the circles are animated for this project.
As you can identify, the flow chart has 2 possible answers, the YES circle or the NO circle.
The YES circle then sequences to the LIAR circle and like the NO circle response they all end up at the final “you need coffee” circle.
Each of those bolded circled items are animated with Scratch code in this project.
The event that initiates this project is clicking on either the YES or NO circle.
As this project comes with no instructions, the coder has animated them at the beginning so as to draw the user’s attention there.
This code is
and when the user actually clicks on that YES circle ( the event)
the following sequence is executed.
The circle grows and shrinks to signify it has been selected ( with the 2 repeat loops, the 1st repeat loop gradually increases the size of the sprite and the 2nd repeat loop shrinks it back again, as the repeat iterators (the value of 10) is the same in each sequence. This creates the animated YES circle which grows and then shrinks back to its original size.
Then a broadcast message ‘yes’ is sent out to all the other sprites in this project to react to.
2. A Broadcast command is a way to get a sprite (or the background) to send a message to all the other sprites in the application.
3.Another sprite in the project needs to have a Receive command block to listen for and act upon that message.
In this project sprite 1 has the ‘when I receive’ block and will execute the sequence of blocks when the particular message in this case the ‘coffee’ message is received
This is an excellent way to coordinate sprites.
4. Conditionals
An easy example of a conditional is an IF statement.
IF (condition) is true.. then the following statement is executed.
Coding is a sequence of events and every so often a decision needs to be made .using a conditional block. The conditional block is used to determine the decision and the subsequent action. If the condition is not met then the code continues on in the sequence.
In the above Scratch code blocks,the IF conditional block is comparing the position of the current sprite or character and another blue colored sprite or background.
If they coincide on the 2 dimensional output screen, then the next statement will be executed. In this example the entire program will be stopped, when the ‘stop ALL’ block is executed.
If the sprite isn’t touching anything blue the action continues, and in this case, it just loops back to the top and tests for this condition forever.
5. Looping
Looping is a key coding concept. Looping comes in 2 major forms
1.repeat a sequence X number of times
or
2.repeat a sequence forever.
Have your students play with this concept in their code.
Take the current code example
https://scratch.mit.edu/projects/78102596/
Firstly let them run the project as is , then change the values in both the expansion and reduction repeat loops. The values can be the same or different in each. let them experiment and report what they observe.
Next have your students change the 2 repeat blocks shown inside the red box with Forever blocks
Soon you’ll all discover that the forever block doesn’t have a bump below it to allow for other code to come afterwards in the sequence.
And so only 1 repeat block, the bottom one; can be swapped for the forever block.
Ask your class “Why is that?” and see if they can find a reason.
Then have them execute this new code segment. And ask them what they observe differently than from before. Tinkering and observation of what results is key in any kind of science to find dependent and independent variables.
They should observe their circle getting infinitesimally small, as time progresses.
Ask them how to get it back to the original size?
One way would be to just drag and drop from the pick list in the center,this set size block to the coding area for that sprite and click upon it.
6. Initialization
Initialization, sets the key parameters of this chopper game.
https://scratch.mit.edu/projects/85036422/
- The size of the chopper needs to be such that the chopper can navigate the upcoming obstacles, so it is set to 25% of the original size.
- The location of the chopper needs to be set so that the player has a chance of winning the game, if the chopper was too close to the ground or the edge, it would crash and end the game prematurely.
- In this game the objective is for the chopper to stay aloft and avoid the scrolling obstacles coming its way.
7. Variables
Variables are coder defined boxes to hold changing values, depending on the project, it could be numbers or strings ( letters), In this case we’ll create a variable called ‘name ‘ to store and display a string that the user types in.
Starting with this Scratch project
https://scratch.mit.edu/projects/86177736/#editor
As you navigate the middle of the interface, click on the data key word.
as you do, the tabs change and you see just 2 more buttons and no variables
1st we create a variable by clicking this button ‘make a variable’ encircled in red.
A new dialog box pops up and gives us 2 things to sort out, the name of the variable and the locality.
To satisfy the pop up dialog we enter a reasonable variable a name, and select for all sprites. it usually works fine this way.
Now we have a variable called ‘name’ we can initialize it or just leave it set to zero, even though later, we’ll put letters into that holding box, as we code this project.
Variables can change as the code is executed, they are temporary place-holders of information of the project.
In this case, the name variable will hold the user entered input (which is stored in answer)when prompted ‘what’s your name?” and print it back out in the ‘say’ block
8. Testing is key,
With any project, testing is key. Many times a project behaves sort of how it should but ‘goes off into the weeds”. That is because of insufficient testing. Have the coder ( student) test their work initially is required, so they can learn and improve their misbehaving code. Then when they are satisfied it works, another student should try and run the project with the coder observing and only observing how the project works. This will give the coder insight on how to better code their project, eliminating a bunch of errors or ‘gotchas’ that they didn’t think to code for.
A simple example would be this project.
https://scratch.mit.edu/projects/86160922/#editor
The code says to ask for the user to type in their name and then display it next to the selected sprite in this case, the sprite character Cassie.
but as you’ll see no name is said , regardless of what is typed into the answer box, it always returns ‘0’.
Why is that?
Its because the ‘answer’ which is returned from the ‘ask’ block and the ‘name’ variable have no relationship.
the built in ‘answer’ variable needs to be assigned to the variable name that the user has defined like so.
so that the final code looks like this:
Have your class try this final code and see if it works for them.
9.pseudo code
Most of us don’t speak code natively; and that’s just fine. When learning to code, it’s best to just understand the problem fully and create a possible solution in pseudo-code. Basically a sequence of statements that leads the computer to solving the problem. Then,when the solution is formed, convert the pseudo-code to Scratch’s language and sequence.
An example of the pseudo code for the blocks above is:
- click on this sprite ( character)
- have the sprite say hello
- wait 2 seconds
- have the sprite ask ‘what’s your name’
- wait for answer
- after the user enters an answer print it out to the user “ hello name”
10. tinkering is important
When instructing your students in coding, allow them to tinker.
Give them an ample 20 minutes to tinker. Have them change the values in any of the blocks of codes, have them change the sequences of their code and see what happens when they restart their projects by clicking on the green flag
They will learn so much more by observing what happens when a value is changed or a sequence is altered.
That is part of the power of MITs Scratch, it allows for tinkering so easily. If the code becomes too buggy the student can either click on the ‘revert’ command to eliminate all changes since he last saved the project or make a copy from the file
or if they wish to fork the project and go another direction and have 2 projects
they can use the ‘save as a copy ‘ selection, which will make 2 copies of the same project and they are free to develop 2 versions of with a similar base.
11. Coding is fun
At the core of any work, we all need it to be fun filled. Coding is creative problem solving. Coding for me is all encompassing.
- it’s a combination of intelligent and creative work.
- I feel like some kind of nerdy superhero.
- Nearly instant gratification.
- The pride of seeing my work used by other people.
- The thing about it that really hooks me is taking a computer that was designed as a general purpose machine and making it do anything I want.
- The benefit that it brings to users in making their lives easier
Gregory Beutler is the Director of Techscool; a tutoring company in Southern California. He’s passionate about teaching kids to code. He can be reached at greg@techscool.org

Learn to Code; Code to Learn