JavaScript Lecture          

Instructor: Amadou O. Wane
Last update: 10/09/01

Lecture6

<html>
<head>
<script language="javascript">
//Method to round up a number
var my_number = Math.round(29.4);
document.write("the number rounded : " + my_number);
var my_array = new Array(10);

solarsys = new Array(9);
solarsys[0] = "Mercury";
solarsys[1] = "Venus";
solarsys[2] = "Earth";
solarsys[3] = "Mars";
solarsys[4] = "Jupiter";
solarsys[5] = "Saturn";
solarsys[6] = "Uranus";
solarsys[7] = "Neptune";
solarsys[8] = "Pluto";

var lastPlanet = solarsys[8];
document.write("<br>Last planet is : " + lastPlanet);
document.write("<br>Last planet is : " + solarsys[8]);
document.write("<br>First planet is : " + solarsys[0]);
//-------------------------------------------------------
var i=0;
for (i=0; i < solarsys.length; i++)
{ document.write("<br>" + solarsys[i]);
}
//-------------------------------------------------------
Horizontal Array. 
Instead of using an index to access data, we use
//a string to access data.
earth = new Array();
earth.diameter = "7920 miles";
earth.distance = "93 million miles";
earth.year = "365.25 days";
earth.day = "24 hours";

document.write("<br>There are " + earth.year + " in a year");
document.write("<br> The length of earth array is " + earth.length);
//-------------------------------------------------------
DOM: Document Object Model
A method is linked to an object. A function is a standalone.
example: document.write(). "Write() is a method, not a function.
Date.getHours(). "getHours" is another example of a method.
A method has an verb as name; an object has a noun as name.
A method is a "function" acting upon an object.
The form object is a child of document.
Document is a child of windows.
Every object in Javascript inherit from Window object.
//--------------------------------------------------------