-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemsObjects.js
More file actions
48 lines (39 loc) · 955 Bytes
/
problemsObjects.js
File metadata and controls
48 lines (39 loc) · 955 Bytes
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
40
41
42
43
44
45
46
47
48
let invoices = {
unpaid: [],
paid: [],
add(name, amount) {
this.unpaid.push({
name,
amount,
});
},
totalDue() {
let total = 0;
this.unpaid.forEach((invoice => total += invoice.amount));
return total;
},
totalPaid() {
let total = 0;
this.paid.forEach((invoice => total += invoice.amount));
return total;
},
payInvoice(name) {
let unpaidInvoices = []
this.unpaid.forEach(invoice => {
if (invoice.name === name) {
this.paid.push(invoice);
} else {
unpaidInvoices.push(invoice);
}
});
this.unpaid = unpaidInvoices;
},
};
invoices.add('Due North Development', 250);
invoices.add('Moonbeam interactive', 187.5);
invoices.add('Slough Digital', 300);
console.log(invoices.totalDue());
invoices.payInvoice("Due North Development");
invoices.payInvoice("Slough Digital");
console.log(invoices.totalPaid());
console.log(invoices.totalDue());