Skip to content

Instantly share code, notes, and snippets.

@ellijayne
Last active June 16, 2018 07:59
Show Gist options
  • Save ellijayne/a450c456076feec4035acbd05798fde2 to your computer and use it in GitHub Desktop.
Save ellijayne/a450c456076feec4035acbd05798fde2 to your computer and use it in GitHub Desktop.
Javascript bank - need help with depositing money function
//create bank //
const bank = [
{name: 'Melanie Sills',
currentBalance: 500
},
{name: 'Susan Oram',
currentBalance: 100
},
{name: 'Paul Adams',
currentBalance: 500
},
{name: 'Brendan Bullock',
currentBalance: 10
}
];
//DEPOSITING MONEY!!//
const deposit = function(money) {
bank[1].currentBalance += money;
return bank[1].currentBalance;
};
deposit(10);
//function to sum up account balances
let summingBank = function(bank) {
let bankSum = 0;
for (var i = 0; i < bank.length; i++) {
bankSum += bank[i].currentBalance;
}
return bankSum;
};
console.log(summingBank(bank));
//function to add new account
let addAccount = function(newName, newBalance){
bank.push({
name: newName,
currentBalance: newBalance,
depositWithdraw: ''
})
return bank;
};
addAccount("Atsuko Wantanabe", 1000);
addAccount("Brenda Barr", 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment