I have the following code.
is this.payment
another property of the car object?
when i want to calculate the price of a car, for example:
var work_car_payments= work_car.payment();
why should i use .payment()
?
payment
hasn't been defined as a function in the code. I'm a little confused.
function get_payment() {
var the_payment = 250;
the_payment += (this.seats == "leather") ? 100 : 50;
the_payment += (this.engine == "V-8") ? 150 : 75;
the_payment += (this.theradio == "CD Player") ? 35 : 10;
return the_payment;
}
function car(seats, engine, theradio) {
this.seats = seats;
this.engine = engine;
this.theradio = theradio;
this.payment = get_payment;
}
var work_car = new car("cloth", "V-6", "Tape Deck");
var fun_car = new car("leather", "V-8", "CD Player");
var custom_car = new car(fun_car.seats, work_car.engine, fun_car.theradio);
var work_car_payment = work_car.payment();
var fun_car_payment = fun_car.payment();
var custom_car_payment = custom_car.payment();
document.write("<h2>The information on the cars you requested:</h2>");
document.write("<strong>Work Car: </strong>");
document.write(work_car.seats + "," + work_car.engine + "," + work_car.theradio);
document.write("<br />");
document.write("<strong>Payments:</strong> $" + work_car_payment);
document.write("<p>");
document.write("<strong >Fun Car: </strong>");
document.write(fun_car.seats + "," + fun_car.engine + "," + fun_car.theradio);
document.write("<br />");
document.write("<strong>Payments:</strong> $" + fun_car_payment);
document.write("</p>");
document.write("<p>");
document.write("<strong>Custom Car: </strong>");
document.write(custom_car.seats + "," + custom_car.engine + ",");
document.write(custom_car.theradio);
document.write("<br />");
document.write("<strong>Payments:</strong> $" + custom_car_payment);
document.write("</p>");