Reputation: 677
In the process of learning JS... it's mai second week from the first day of JS and i have that big problems with syntax
function Customer(name, street, city, state, email, balance) {
this.name = name;
this.street = street;
this.city = city;
this.state = state;
this.email = email;
this.balance = balance;
this.payDownBal = function(amtPaid) {
this.balance -= amtPaid;
};
this.addToBa = function(amtCharged) {
this.balance += amtCharged;
};
}
var cust2 = new Customer("Sally Smith", "234 Main ", "Pittsburgh", "PA", "[email protected]", 0.00);
cust2.addToBal(15.50);
Customer.prototype.isCreditAvail = true;
Customer.prototype.toString = function() {
return this.name + " lives at " + this.street + " in " +
this.city + " " + this.state + " email : " + this.email +
" and has a balance of $ " + this.balance.toFixed(2) + "Creditworty : " + this.isCredAvail;
}
document.write(cust2.toString());
I can't find the error...can i be helped please ?
Upvotes: 0
Views: 54
Reputation: 550
You made a simple mistake. You defined addToBa() function and you are calling function addToBal() which is not defined.
Change the line 17 to call the function addToBa(). (or change the function declaration to addToBal()).
Upvotes: 1
Reputation: 551
Well, look at line 11 closely, your function declaration:
this.addToBa = function (amtCharged) {
and line 17:
cust2.addToBal(15.50);
It's a typo, "addToBa" on line 11 should be "addToBal".
(Also, there's another typo that won't allow the "isCreditAvail" TRUE boolean value to be referenced in your toString function, on the 3rd-to-last line... change "this.isCredAvail" to "this.isCreditAvail").
Upvotes: 1