Introduction to Coding

Contributor: Jay Gregorio. Lesson ID: 13188

What do Minecraft, YouTube, Facebook, and Instagram have in common? These platforms use languages that keep us all connected! Learn universal coding concepts that give life to our digital world!

categories

Computer Science, Software and Applications

subject
Technology
learning style
Auditory, Kinesthetic, Visual
personality style
Beaver, Golden Retriever
Grade Level
Middle School (6-8), High School (9-12)
Lesson Type
Quick Query

Lesson Plan - Get It!

Audio: Image - Button Play
Image - Lession Started Image - Button Start

I'm sure you have used a microwave oven before. Without even thinking, you open its door, put the food in, close the door, and press the number. Then, the microwave oven will do its job by running the motor which rotates the glass plate.

As soon as it turns, the microwave energy will cause the water molecules in your food to vibrate. This vibration will increase friction among these molecules, eventually resulting in heat. When the timer is up, the rotating plate stops, and the alarm dings to remind you that its job is complete!

  • What if you were asked to tell someone how to use the microwave oven?
  • What specific instructions would you give?

Perhaps it would be helpful to keep your instructions very specific in a step-by-step process as shown below.

  1. Place the food item in a microwaveable container.
  2. Open the door of the microwave oven.
  3. Place the food on the middle of the rotating glass plate inside the oven.
  4. Close the door of the microwave oven.
  5. Press the number of minutes that you want the food to be heated; then press START.
  6. When the alarm dings, open the microwave oven and get your food.

Your interaction with the microwave oven is somewhat similar to the operational characteristics of coding: it involves a series of inputs and outputs.

Opening and closing the door, punching in the number of minutes, and pressing the START button describe the inputs triggered by you as a programmer. By performing these inputs, you expect the microwave oven to perform specific functions such as opening and closing the door, running for the allotted time, rotating the glass plate, ringing the alarm, and ultimately heating the food!

In this lesson, you will discover that there is more to coding than a simple set of instructions. Let's get started!

What Is Coding?

The step-by-step instructions on how to operate a microwave oven may sound simple enough, but we have a problem. Computers are unable to read this type of numbered instruction. For example, when you open the door of the microwave oven, the oven's response is not simply allowing you to open it but also to stop emitting microwaves.

In other words, you have one input which is opening the door, and the microwave has multiple outputs which are allowing you to open the door, turning on the light, and stopping microwave emission.

  • Sound complicated?

Let's break it apart further!

In the same way as the microwave oven, we ask the computer to do a lot of different things, from sending emails to playing games. In reality, computers do not really know what to do by themselves.

They need computer programmers to give them a set of instructions in the form of numbers, letters, symbols, or a combination of these. These instructions are called machine codes.

computer binary code

The number codes you see in the above photo do not make a lot of sense to humans. To make it easier for us and the computer to understand the instruction, a programming language is used.

  • Have you heard of JavaScript, HTML, CSS, and Python?

These are just four out of the 698 programming languages that are currently used. Codes are easier to understand because of these languages. For instance, you want the computer to say, "Hello, world." Instead of using a set of numbers or symbols, you can use a programming language as shown below.

Python code example

  • Isn't that easier to understand?

Almost all programming languages work the same way.

  1. Write the input code and tell the computer what to do: print ("Hello, world")
  2. The code is compiled to a language that the computer understands.
  3. The computer executes the code and writes the output "Hello, world" back to you.

In summary, coding is the process of using a programming language to tell the computer what to do.

In the above sample code, there is only one line of instruction. If you want the computer to do more, then multiple lines are written. A document full of lines of code is called a script.

When you see a post on Facebook, for instance, you can press a button to like it, love it, or choose an emoji that perfectly describes your reaction to the post.

  • Can you imagine what the script would be just for this task?

The programmer had to create multiple lines of codes to give instructions to the computer for it to respond to the type of reaction you choose. Once the script is compiled and executed, the programmer can save the script as part of the entire Facebook program. Other apps, websites, and even the online games you play are examples of computer programs.

Learning How to Code

Even if you are confident in your knowledge of the fundamentals of coding, it requires advanced knowledge to use JavaScript, HTML, CSS, or Python. Fortunately, there are some programs that will help us perform the same task. It is called block-based coding!

Block-based coding or block based-programming is coding within a programming language where instructions are mainly represented as blocks.

block-based coding example

The example above was created using Scratch, which is a block-based visual programming language and an online community. On this website, you can use a block-like interface to create interactive stories, games, and animations.

Code.org is another program that teaches coding. Here, visual blocks can be dragged and dropped to write programs. These programs deliberately use the idea of algorithms. An algorithm is a set of steps that can be followed from start to finish to complete a task.

In block-based coding, you continue to add blocks in order to direct the sequence of events that you want the computer to perform. Here is another more complex example created using Scratch.

block-cased coding example

You can create free accounts at either (or both!) of these websites to explore and learn more about block-based programming!

Time to head over to the Got It? section to explore different activities that will help you understand the basic computer-coding processes behind every program we enjoy today.

Image - Button Next