-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects-references.js
39 lines (32 loc) · 995 Bytes
/
objects-references.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
let myAccount = {
name: 'Maxs Account',
expenses: 0,
income: 0,
};
// let otherAccount = myAccount; // This hooks up to myAccount
// otherAccount.income = 1000; // Then you can change myAccount by referencing otherAccount
// Expenses
let addExpense = function (account, amount) {
account.expenses = account.expenses + amount
};
// Income
let addIncome = function (account, income) {
account.income = account.income + income
};
// Reset Account
let reset = function (account) {
account.expenses = 0,
account.income = 0
};
// Account Summary
let getAccountSummary = function (account) {
let balance = account.income - account.expenses
return `${account.name} has $${balance}. $${account.income} in income and $${account.expenses} in expenses`
};
addExpense(myAccount, 180.94);
addIncome(myAccount, 3600);
console.log(myAccount);
console.log(getAccountSummary(myAccount));
reset(myAccount);
console.log(myAccount);
console.log(getAccountSummary(myAccount))