-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassAndObject Example.js
More file actions
55 lines (46 loc) · 1.18 KB
/
ClassAndObject Example.js
File metadata and controls
55 lines (46 loc) · 1.18 KB
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
49
50
51
52
53
54
55
class invoice {
invoiceNumber = 0;
invoiceAmount = 0;
}
class person {
firstName = "";
lastName = "";
email = "";
invoices = [];
fullName() {
return firstName.trim() + " " + lastName.trim();
}
getInvoiceTotal() {
var total = 0;
for (let index = 0; index < invoices.length; index++) {
total = total + invoices[index].invoiceAmount;
}
return total;
}
}
var namesArray = [];
function SavePerson(firstName, lastName, email) {
var p = new person();
p.firstName = firstName;
p.LastName = lastName;
p.email = email;
var inv1 = new invoice();
inv1.invoiceNumber = 1;
inv1.invoiceAmount = 500;
p.invoices.push(inv1);
var inv1 = new invoice();
inv1.invoiceNumber = 2;
inv1.invoiceAmount = 25;
p.invoices.push(inv1);
namesArray.push(p);
}
function ListPeople() {
for (var index = 0; index < namesArray.length; index++) {
var p = namesArray[i];
console.log(p.fullName()
+ " "
+ p.email
+ " invoice total: $"
+ p.getInvoiceTotal());
}
}