Im building a bankAccount program and trying to add my DDs into the global var, but as I create new objects from my constructor function then add them into bankAccount it only shows the last created dd?
What im trying to do is push all DD into bankAccount..
Code is below
// Created my bankAccount with the value of 0
var bankAccount = {};
// Object constructor to created direct debit with name and cost
function DirectDebit(name, cost) {
this.name = name;
this.cost = cost;
}
// Creating a new DD for my phone
var phone = new DirectDebit("Phone ", 20);
var car = new DirectDebit("Car ", 250);
function addToBank (dd) {
bankAccount = dd
}
addToBank(phone)
addToBank(car)
console.log(bankAccount);
this outputs:
DirectDebit { name: 'Car ', cost: 250 }