Javascript Programming: Part 3

Basic Programming Concepts: continued

Computers can only understand ‘yes’ and ‘no’ – without the help of software/programs. If we go into a little more nerd detail, we see that computers actually see ‘yes’ and ‘no’ as 1 and 0. Once again we can say that programs are sets of written instructions telling computers what to do.

Because of how stupid computers really are, programmers (a.k.a.: nerds) over the years have written programs that make it much easier for us to ‘talk’ to computers. One of these programs that make our lives easier is the web browser.

Built into Internet Explorer, Netscape, and most other web browsers is the ability to understand a programming language called JavaScript. With JavaScript we can indirectly control the computer.

I hope that this basic explanation of programming clears things up a little for all of you reading.

Ok, that is a lot of abstract information to take in, let’s look at something a little more concrete.

Are HTML and CSS programming?

We know by now that HTML and CSS are used to build web pages. This is a question that comes up from time to time; since HTML and CSS are essentially just lots of code that is used to tell the browser what to display (HTML) and how to display it (CSS), isn’t it programming? The answer is ‘NO’, and this is why:

The fundamental difference between coding (ex: HTML, CSS) and programming (JavaScript, Java) is that in programming you can make decisions based on something happening.

For instance, you can write a little JavaScript that causes a small message box to appear if the user (the person looking at your page) does something. This can be clicking on a button or pressing on the ‘C’ key on the keyboard etc.

This is of course a simplification of the situation but it essentially covers it. It can get confusing because in the world of the Internet there can be a ‘gray’ area where without using programming you can get the browser to do something on its own. An example of this is the META tag ‘refresh’. This tag allows you to tell the web page to reload itself or to load an entirely new page after a specified number of seconds or minutes. Here’s what the META tag ‘refresh ‘ looks like:

<meta http-equiv='refresh' content='3; URL='>

This tag tells the browser to load the page: after 3 seconds.

Some people will get a little confused and say that since the META tag code is telling the browser to do something, it is programming. Right? Wrong!! The reason that it is not programming is because there is no decision being made. No matter what else may happen (as long as they stay on the page for at least 3 seconds) the page will automatically load the website in the Meta tag (in this case: ).

To make this example act like it was truly programmed, you would have to be able to (for example) control if the browser would reload the page or some other page depending on, say, what the user did on the page.

An easy example: say you had a box on your web page where the user could enter in a number, and depending on the number entered, the browser would load a particular page.

This shows how programming allows you to make decisions based on as many possibilities you want.

One more example: you can, with JavaScript, check to see what browser the user is using to view your web page and what time of the day it is. So with this information you can send people to a particular website if it is, say, before 12 pm and they are using Internet Explorer as their browser. And you can also program to send them to another web site if it is past 12 pm and they are using Netscape. Any combination is possible and that is the power of programming!

A final point

This is just the first part of this series, in the second part I will slowly introduce you to more concepts that will give you the foundation you need to get into some real programming. With just a little patience, in no time, you all will be programming!