Programming: Html and Web Page Essay

Submitted By darkdreammachine
Words: 2797
Pages: 12

What is Javascript?
Javascript is the programming language available in everybody’s internet browser: Internet Explorer, Chrome, Firefox, Safari, Opera, ...
Javascript is not the programming language Java (but it looks similar to it).
Javascript consists of a sequence of instructions that the browser interprets.

Where are these instructions?
The instructions, the Javascript programming code, are in the web page that the browser displays on your screen. Specifically, the instructions are mixed in with the HTML in two different ways:

1 – between beginning and ending script tags:

... javascript instructions go here

2 – on the right hand side of the equal sign in some HTML tag attribute clauses:
For example:

The stuff to the right of the equal sign: alert('Mouse over Frodo'); is a javascript instruction.

Here is an HTML page with a little Javascript in it:

My Page

alert ("Hello world.");

Exercise 1.

Type the HTML page above into a brand new document called hello.html. Open it with your browser and observe what happens.
Make a second copy of hello.html, call it hello2.html. Add another alert line with your name between the quote marks instead of Hello world. Open hello2.html with your browser and observe what happens. Congratulations. You are programming!

A note about the exercise:

If you have difficulty and get an error, carefully check that each symbol has been copied correctly from the text.

The javascript code is just the lines containing alert.

alert is a javascript command for the browser to display the text that follows it – between quote marks - " " - which are between parentheses - ( ) the alert command has a semicolon - ; - after the right parenthesis

Question: How is this web page different from your usual web browsing experience?

What is Javascript programming good for?

Interacting with the viewer of the web page
Creating dynamic (moving) content, changing the web page
Creating different content based on different situations
Calculating with numbers, manipulating text and images

Exercise 1 gave a simple example of output from a program and forced you to click a button (input) to carry on. In this example there is no input required from the user. The program just makes the browser display a normal looking web page.

My Page

document.write("Goodbye alert boxHello world."); document.write("Again, we say goodbye!");

Exercise 2.

Type the above web page into a file helloworld2.html and view it with your browser.

Question: What do you notice about the spacing?
Question: To make Again, we say goodbye! appear on a different line, what would you have to do?

A note about this exercise:

The javascript document.write ("Goodbye alert boxHello world."); makes the browser put Goodbye alert boxHello world. on the web page. The browser breaks the line just where the occurs. Again, we say goodbye! continues on the same line.
Exercise 3.
Create a new web page with a verse from your favourite poem, rhyme, limerick... using document.write and to make line breaks. If you have more than one verse, you can use to start each new verse.

Summary
Javascript appears between the script beginning and ending tags: and

Javascript can also appear on the right hand side of the equal sign in a tag attribute. To see an example, open the file frodo.html with your browser.

Two methods of output using Javascript: alert (" ... "); puts up a dialog box document.write (" ... "); writes onto the web page the user sees.

Javascript Variables
A variable is a named place in the memory of the computer. A variable stores information. Some of the types of information that can be stored are:
Numbers
Text
Dates

To introduce a variable use the keyword var followed by the name of the variable. Optionally, give the variable a starting value.

Examples:…