|
@@ -0,0 +1,48 @@
|
|
|
|
|
+const account = {
|
|
|
|
|
+ name: 'Andrew Mead',
|
|
|
|
|
+ expenses: [],
|
|
|
|
|
+ income: [],
|
|
|
|
|
+ addExpense: function (description, amount) {
|
|
|
|
|
+ this.expenses.push({description, amount})
|
|
|
|
|
+ },
|
|
|
|
|
+ addIncome: function (description, amount) {
|
|
|
|
|
+ this.income.push({
|
|
|
|
|
+ description: description,
|
|
|
|
|
+ amount: amount
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ getAccountSummary: function () {
|
|
|
|
|
+ let total = 0
|
|
|
|
|
+ let totalIncome = 0
|
|
|
|
|
+ let totalExpenses = 0
|
|
|
|
|
+
|
|
|
|
|
+ this.expenses.forEach(function(expense) {
|
|
|
|
|
+ totalExpenses = totalExpenses + expense.amount
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ this.income.forEach(function(income){
|
|
|
|
|
+ totalIncome = totalIncome + income.amount
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ total = totalIncome - totalExpenses
|
|
|
|
|
+
|
|
|
|
|
+ return `${this.name} has a balance of $${total}. $${totalIncome} in income. $${totalExpenses} in expenses.`
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// Expenses --> description, amount
|
|
|
|
|
+// addExpenses - description, amount
|
|
|
|
|
+
|
|
|
|
|
+// getAccountSummary - total up all expenses --> Andrew Mead has $1250 in expenses.
|
|
|
|
|
+
|
|
|
|
|
+// 1. add income arrray to account
|
|
|
|
|
+// 2. add income method -> description, amount
|
|
|
|
|
+// 3. Tweak getAccountSummary
|
|
|
|
|
+
|
|
|
|
|
+// Andrew Mead has a balance of $10. $100 in income. $90 in expenses.
|
|
|
|
|
+account.addExpense('Rent', 950)
|
|
|
|
|
+account.addExpense('Coffee', 2)
|
|
|
|
|
+account.addIncome('Job', 1000)
|
|
|
|
|
+console.log(account.getAccountSummary())
|
|
|
|
|
+console.log(account.expenses)
|
|
|
|
|
+console.log(account.income)
|