headings, lists, tables, paragraphs, links, images.Of course, it includes some text formatting features, too, like
So, many people want to create dynamic or interactive pages that can change in response to the user. Many possibilities:
First, if we look at an example of JavaScript (click here), we see that it has some resemblance to English -- it's certainly readable by humans, at least. This presents a problem: can computers understand this piece of text? No, not really: they can execute instructions, but only a very limited set of instructions in very very specific form (in fact, computer instructions are just sequences of 0's and 1's.
So, we type in this JavaScript program which we can read, but the computer only understands 0's and 1's. So how is the computer able to execute our program?
There are essentially two answers to this question:
JavaScript programs have to respond to the user: moving the mouse, clicking things, maybe typing some stuff into boxes, etc. Programming that is done to work in this context is usually called Graphical User Interface programming, or GUI programming. Most JavaScript programming has this flavor.
First we will need to learn how to include buttons and text boxes on a web page. That involves more HTML tags.
In a GUI setting, the program generally waits for the user to tell it what to do (by, say, pressing a button or clicking a mouse). These actions are called events. After we learn how to create buttons and text boxes, we will learn how to use JavaScript to respond to events.
Here's a simple example. There's a very small mistake in this script -- a missing quotation mark. This kind of pickiness is a pain. Fortunately, there is one tool available that help you catch at least some of these mistakes. In your browser (Note! this is only guaranteed to work with Netscape Navigator!!), open a new page called javascript: (don't forget the colon). This opens a new window called the JavaScript console; in this window your browser will provide some information about JavaScript errors. When you're working on JavaScript assignments for this class, you'll probably want to keep the JavaScript console open all the time. (Another note: depending on how your browser was set up, it's possible that the javascript console will automatically appear every time there's an error; if this happens to you, you're in luck, as far as this class goes.)
So far, we haven't actually written very much JavaScript, but already there are a number of important rules to be aware of: