Bank details using javascript oop

Bank details using javascript oop
0

#1

My result should be: owner : John, balance : 1000
owner: Tobi, balance: 1000
owner; Mike, balance :1000.
please how do I complete this,I,ve been stock here for the past 2 days

class bank {
  constructor(name) {
    this.name = name;
    this.balance = 0;
  }
 
  credit(value) {
    
    this.balance += value;
    return this.balance;
  }
  describe() {
    return `owner : ${this.name}`;
  }
  
}
const acct1 = new bank("John");
const acct2 = new bank("Tobi");
const acct3 = new bank("Mike");
acct1.credit(1000)
console.log(acct1.describe())// owner: John

#2

Well, you’re only returning the name


#3

The problem is I don’t know how to return the balance


#4

Exactly the same way you return the name, just put the balance in that string as well


#5

Thanks it’s working now but this isn’t exactly the way I am been told to do it.Maybe you can help me out.
This is the question:
A balance property, initially set to 0.
A credit method adding the value passed as an argument to the account balance.
A describe method returning the account description.
Write a program that creates three accounts: one belonging to Sean, another to Brad and the third one to Georges.
These accounts are stored in an array. Next, the program credits 1000 to each account and shows its description.


#6

Can you post your updated code and let us know which parts are not working as intended?


#7

class bank {
constructor(name) {
this.name = name;
this.balance = 0;
}

credit(value) {

this.balance += value;
return this.balance;

}
describe() {
return owner : ${this.name}, balance: ${this.balance};
}

}
const acct1 = new bank(“Sean”);
const acct2 = new bank(“Brad”);
const acct3 = new bank(“Georges”);
acct1.credit(1000)
acct2.credit(1000)
console.log(acct1.describe())
console.log(acct2.describe())


#8

In your original post, you said you’re being asked to return a string like owner: Tobi, balance: 1000. To return that string you have to return that string, there isn’t another way to do that because anything else involves not returning the string. So that bit has to be correct, it’s impossible to do it any other way.

The next bit, write a function or functions to creates three instances of the classes then operates on them; the description isn’t totally clear, but you can just loop over an array of names and turn it into an array of class instances (bank.new(name)) or whatever

The reason I say it’s unclear is that the name of the class is Bank, which implies that what you’ve written should be called Account, or Customer, and it there should be a Bank with many Account/Customer/etc objects