welcome

Web Programming Primer

-Lesson 11-







Introduction to JavaScript

Intro

As stated on w3scools.com, Javascript it programming code that can be inserted into HTML pages. If you have never learned any coding languages or have no previous experience with programming, this may be a little confusing at first, but you will understand it in no time. Programming is basically just constructing an ordered set of instructions to enable a computer to perform a task. JavaScript can transform a static page into a dynamic page. Instead of having a page of non-responsive text and pictures, you can have a responsive, interactive page.

Getting Prepared

The first thing to learn about JavaScript is that it is not similar in concept to XHTML or CSS, so move all that you learned thus far to the side. Now that we have an empty slate, let's begin. When coding, you will code by statements, one line of code at a time. In JavaScript, you end each line of code with a semi colon. This is a part of what is termed its "syntax." Syntax is the way words, phrases, and elements are pieced together in a proper way to make a cohesive, orderly system. In other words, there are certain words, characters, and patterns of arranging elements that you must know in order to properly create lines of JavaScript code, or else it will not run properly. We will discuss the JavaScript syntax along the way.

When we type lines of code, we will be taking a problem step by step, and breaking it down. When we have a completed algorithm, we will run the program (load the page in a browser), view the outcome, and fix any errors.

This is all you need to know about what JavaScript is for right now. We will simply dive in to application, and as you watch what can be accomplished through its use, you will begin to understand what programming is really all about. Go ahead and dive in, do not be afraid, you will get it.

Time to Jump In

You will code all of your JavaScript in your .html document. As you should know, anything in XHTML must be constructed inside of tags, so, this applies to entering JavaScript in the document as well. All the JavaScript will need to be coded inside of "script" tags. You can embed these in the body. Inside the opening script tag, you must type the attribute "type" and set it equal to "text/javascript".

It should look like this:


Now that we know where to type the JavaScript, we will learn our first line of code.

How to Write

JavaScript won't inherently do anything to your site until you tell it to. What I mean is, you can type a lot of code out, but not have it affect your page in anyway. But, that is not the point, we want to use JavaScript to effect our page, so you will learn one way of doing that right now.

There is a command you can use to make JavaScript write something out on the display screen. By typing: document.write("your text"); in the script tags, you can have JavaScript write whatever text you want to be displayed. This may seem useless right now. You may say, "Why wouldn't I just type this text using XHTML?", but this will have much greater value later on when you learn more complex coding.

This is what it looks like:



Try it out for yourself. Whatever you type between the quotation marks should be displayed on screen.


Lesson: 11 12 13 14 15

Back Next
This page was constructed by Isaac Duke, a student of Anderson University, for an independent study in web programming. This is not a fully comprehensive primer, so use in conjunction with other resources (resource page provided). The last time this site has been updated was on August 20, 2013. If any questions, email misaacduke@gmail.com