Having trouble with this assignment. Can someone help me out with this? I don't get it! For my assignment it wants me to create a constructor function name automobile w/ 5 properties. Assign the values of my car to each automobile property. Print to the screen.

This 1st one is what I gather from the book that I need to do. Mind you for some reason they can't put all the steps together on a page so I'd know what it should actually look like...

I've tried a showOrder() method but my book doesn't clearly explain it and I can't get it to work no matter where I try it.

I really appreciate the help that I receive on this forum. Hopefully you guys can help me grasp this stuff over time. This is going to be my last assignment until after the first of the year. Thanks in advance.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Candy Order</title>
</head>
<body>

<script type="text/javascript">
<!--HIDE FROM INCOMPATIBLE BROWSERS

function CandyOrder(customer, candy, boxes) {
	this.customerName = customer; //customer name
	this.candyType = candy; // chocolate, caramel
	this.numBoxes = boxes; // number of boxes
}



function displayCandyOrder() {
	document.write("<p>Customer name: " + this.customerName);
	document.write("<br />Candy type: " + this.candyType);
	document.write("<br />Quantity: " + this.numBoxes + " boxes</p>");

var valentinesDay = new CandyOrder();
valentinesDay.customerName = "Don";
valentinesDay.candyType = "choclate";
valentinesDay.numBoxes = 5;
document.write(<p>Customer name: " + valentinesDay.customerName);
document.write("<br />Candy type: " + valentinesDay.candyType);
document.write("<br />Quantity: " + valentinesDay.numBoxes + " boxes</p>");

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>



</body>
</html>

Here is what I was planning on using...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Automobile</title>
</head>
<body>
<script type="text/javascript">
<!--HIDE FROM INCOMPATIBLE BROWSERS

function automobile(make, model, year, engine, drive) {
	this.make = Jeep;
	this.model = Wrangler;
	this.year = 2004;
	this.engine = 4.0;
	this.drive = 4X4;
}

	document.write("<p>Vehicle make: " + this.make);
	document.write("<br />Vehicle model: " + this.model);
	document.write("<br />Vehicle year: " + this.year);
	document.write("<br />Vehicle engine: " + this.engine);
	document.write("<br />Vehicle drive: " + this.drive + "</p>");

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>

</body>
</html>

In your constructor, make, model and drive are all wrong. You MUST put apostrophes (or double quotes) around the values because those values are STRING values - ex:
WRONG: this.drive = 4X4; CORRECT: this.drive = '4X4'; So fix the above three statements first.

As for lines 19-23, you CANNOT use this.XXX (where XXX is any of the automobile properties) because those document.write statements are NOT being executed within a method of automobile nor within the constructor. On line 18 put the following:

var c = new automobile('Ford','Mustang',2010,4.0,'FWD');

then in lines 19-23 change [B]this.XXX[/B] to [B]c.XXX[/B]

Thank you Hielo. I got it to work with your help. Here is what I ended up with.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Automobile</title>
</head>
<body>
<script type="text/javascript">
<!--HIDE FROM INCOMPATIBLE BROWSERS

function automobile(make, model, year, engine, drive) {
	this.make = "Jeep";
	this.model = "Wrangler";
	this.year = 2004;
	this.engine = "4.0";
	this.drive = "4X4";
}


var tj = new automobile("Jeep", "Wrangler", 2004, "4.0", "4X4");
	document.write("<p>Vehicle make: " + tj.make);
	document.write("<br />Vehicle model: " + tj.model);
	document.write("<br />Vehicle year: " + tj.year);
	document.write("<br />Vehicle engine: " + tj.engine);
	document.write("<br />Vehicle drive: " + tj.drive + "</p>");

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>

</body>
</html>

the problem with what you have now is that if you were to change: var tj = new automobile("Jeep", "Wrangler", 2004, "4.0", "4X4"); to: var tj = new automobile("Jeep", "Cherokee", 2010, "4.0", "4X4") ;

then the output would NOT reflect the changes. It will always show Wrangler as model and 2004 as year. This is because in your constructor you hard coded those values. Instead, what you need to do is change lines 12-16 so that the value assigned to the object properties are NOT the hard coded values, but INSTEAD use all the parameters in automobile - ex: this.make = make;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.