Learning to Code – Programming 101

Programming is the process of writing code for the computer to execute. It’s like writing a command and giving it to someone so that he can perform the task. When you write the code, your computer will do exactly what you tell it and therefore, writing a good program will have a great difference between writing an excellent program. Your programming skill will determine how efficient your program will be, thus, best coding practices are taught early to the students of computer programming in order to ensure a quality final product.

Levels of Programming

 

There are two levels of programming namely low-level and high-level. Low-level programming languages are often more difficult to learn because of their closeness to hardware. However, learning a low-level programming language will allow you to understand how computers function and will provide you with a greater wisdom in programming. Examples of low-level programming languages are C, C++ and Assembly. In addition, low-level programming languages can create faster programs than higher level programming languages.

High-level programming languages are programming languages that are “far” from hardware. They are easier to learn than low-level programming languages however, they tend to produce slower final products. Well, the difference is not huge anymore nowadays and when I mean slower, it’s only in a matter of milliseconds. Examples of high-level programming languages are JavaScript, Java, PHP and Python.

Simple Programming – JavaScript

I’ll teach you the very basic of programming. On this lesson, we’ll use JavaScript. Why JavaScript? There are some key points:

  • No need for additional software
  • All you need is a text editor and your browser
  • The code structure is easy to understand
  • Derived from C

Simple Programming Basics

Open a notepad (if you’re on windows, I suggest notepad++ and on mac, textedit) and save it as program.js. Then we will create another file and save it as test.html file and put the following content inside the html file then save it. The test.html and program.js file must be in the same directory.

<html>

<head>

<title>Test Page</title>

<script src="program.js"></script>

</head>

<body>

This is a test page

</body>

</html>

A Simple Code

Now, open the program.js file and put the following:

var name="Erik";

 

if(name=="Erik") {

alert("You're Erik!");

}

else {

alert("You're not Erik!");

}

We will explain them one by one. The var is called a reserved keyword and that means it’s a part of the JavaScript programming language. What it does is it tells JavaScript that you are create a variable which is called “name”. A variable is like a container that can hold a data and the data that we assigned for the variable called name is Erik.

Now, we create a condition here using the if keyword. The condition says that if the variable called name’s content is equal to Erik, then it will create a popup that says “You’re Erik”, but if the variable’s value’s content is other than Erik, then it will popup “You’re not Erik”.

Try opening the test.html using your browser and you’ll see that it will popup “You’re Erik”. Now open the program,js and change the value of name to other data and you’ll get “You’re not Erik” as a popup.