Create and display custom objects using JavaScript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JavaScript - Create and Display Object Types</title>
</head>
<script language="JavaScript">
 
// ************************************************************************
// CREATE AN AUTOMOBILE USING A CONSTRUCTOR
// ************************************************************************
function Automobile(manufacturer, model, series)
{
 
 
    // ************************************************************************
	// DEFINE AUTOMOBILE ATTRIBUTES
	// ************************************************************************
    this.manufacturer= manufacturer;
    this.model = model;
    this.series = series;
 
}
 
 // ************************************************************************
// DEFINE BEHAVIOR TO RETURN AUTOMOBILES
// ************************************************************************
function getAutomobileInfo()
{
 
 // ************************************************************************
// CREATE VARIOUS AUTOMOBILES OBJECTS
// ************************************************************************
 
	astonMartin1 = new Automobile("Aston Martin", "DB", "DB9 Sports Pack");
	astonMartin2 = new Automobile("Aston Martin", "DB", "DB RS9");
	astonMartin3= new Automobile("Aston Martin", "Vanquish", "V12 S");
	astonMartin4 = new Automobile("Aston Martin", "Vanquish", "Roadster");
 
	bmw1 = new Automobile("BMW","M Series","Coupe");
	bmw2 = new Automobile("BMW","M Series","Convertible");
	bmw3 = new Automobile("BMW","Z Series","Roadster");
	bmw4 = new Automobile("BMW","Z Series","Z3");
 
	jaguar1 = new Automobile("Jaguar","X-Type","Sedan");
	jaguar2 = new Automobile("Jaguar","X-Type","Wagon");
	jaguar3 = new Automobile("Jaguar","XK","Roadster");
	jaguar4 = new Automobile("Jaguar","XK","RS");
 
	mercedesBenz1 = new Automobile("Mercedes Benz","SLR","350");
	mercedesBenz2 = new Automobile("Mercedes Benz","SLR","55");
	mercedesBenz3 = new Automobile("Mercedes Benz","SL-Class","SL600 Roadster");
	mercedesBenz4 = new Automobile("Mercedes Benz","SL-Class","SL65 AMG Roadster");
 
	porsche1 = new Automobile("Porsche","911","Turbo");
	porsche2 = new Automobile("Porsche","911","GT#");
	porsche3 = new Automobile("Porsche","Boxster","2.5");
	porsche4 = new Automobile("Porsche","Boxster","S");
 
// ************************************************************************
// PRINT AUTOMOBILE OBJECTS ONTO WEB PAGE
// ************************************************************************
 
    document.write("Manufacturer:" + astonMartin1.manufacturer + "<br>" +
    			   "Model :" + astonMartin1.model + "<br>" +
    			   "Series :" + astonMartin1.series + "<br><br>");
 
    document.write("Manufacturer:" + astonMartin2.manufacturer + "<br>" +
    			   "Model :" + astonMartin2.model + "<br>" +
    			   "Series :" + astonMartin2.series + "<br><br>");
 
    document.write("Manufacturer:" + astonMartin3.manufacturer + "<br>" +
    			   "Model :" + astonMartin3.model + "<br>" +
    			   "Series :" + astonMartin3.series + "<br><br>");
 
    document.write("Manufacturer:" + astonMartin4.manufacturer + "<br>" +
    			   "Model :" + astonMartin4.model + "<br>" +
    			   "Series :" + astonMartin4.series + "<br><br>");
}
 
 
 
 
</script>
</head>
 
<body bgcolor = "#FFFFFF">
 
<!-- INSERT JAVASCRIPT TO CALL BEHAVIOR-->
<script language="JavaScript">
 
	getAutomobileInfo();
 
</script>
 
</body>
</html>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.