Last active
June 16, 2018 07:59
-
-
Save ellijayne/a450c456076feec4035acbd05798fde2 to your computer and use it in GitHub Desktop.
Javascript bank - need help with depositing money function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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