0

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 ?

3
  • 2
    What makes you think there is an error? Did you get an error message? If so what is it? Stack Overflow is not a place where you can just post a big chunk of code and expect others to fix it for you. Explain the issue and provide relevant information. See How to Ask. Commented Feb 5, 2016 at 22:03
  • next post it will be more specified , thanks for your advices Commented Feb 5, 2016 at 22:07
  • You don't have to wait till your next post, you can edit this one :) Commented Feb 5, 2016 at 22:08

2 Answers 2

1

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()).

Sign up to request clarification or add additional context in comments.

Comments

1

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").

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.