The Abc of Programming

Hello,

This is the third course of the JavaScript series I’ve started. If you have missed them, you can check them “Introduction to JavaScript” and “HTML and CSS: A quick refresher” courses.

In this course, we will cover the basics of programming. Basically we will answer the following questions: What is script? How do computers understand our world, how do we communicate with computers?

What is a Script?

A Script is a series of instructions that a computer can follow to achieve a goal. 

A browser may use different parts of the script depending on how the user interacts with the web page. 

Scripts can run different sections of the coe in response to the situation around them.

Writing a script

To write a script, you need to first state your goal and then list the tasks that need to be completed in order to achieve it. 

Start with the big picture of what you want to achieve, and break that down into smaller steps. 

  1. Define the script
    1. First, you need to define the task you want to achieve. You can think of this as a puzzle for the computer to solve.
  2. Design the script
    1. To design a script you split the goal out into a series of tasks that are going to be involved in solving this puzzle. This can be represented using a flowchart. 
    2. You can then write down individual steps that the computer needs to perform in order to complete each individual task (and any information it needs to perform the task), rather like writing a recipe that it can follow.
  3. Code each step
    1. Each of the steps needs to be written in a programming language that the computer understands. In our case, this is JavaScript. 

As tempting as it can be to start coding straight away, it pays to spend time designing your script before you start writing it. 

 

Computers Create models of the world using data

Here is a model of a hotel, along with some model trees, model people and model cars. To a human, it is clear what kind of real-world object each one represents.

objects

Objects and Properties

Objects (Things)

In computer programming, each physical thing in the world can be represented as an object. There are two different types of objects here: a hotel and a car. 

Programmers might say that there is one instance of the hotel object, and two instances of the car object. 

Each object can have its own: 

  • Properties
  • Events
  • Methods 

Together they create a working model of that object. 

Properties (Characteristics)

Both of the cars share common characteristics. In fact, all cars have a make, a color, and engine size. You could even determine their current speed. Programmers call these characteristics the properties of an object. 

Each property has a name and a value, and each of these name/value pairs tells you something about each individual instance of the object. 

The most obvious property of this hotel is its name. 

The value for that property is Quay. You can tell the number of rooms the hotel has by looking at the value next to the rooms property.

Screen Shot 2020-04-16 at 11.59.38 AM.png
Hotel and Car objects with their properties

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s