-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathah_report.js
100 lines (80 loc) · 2.29 KB
/
ah_report.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"use strict";
/*
New Perspectives on HTML5 and CSS3, 7th Edition
Tutorial 10
Case Problem 3
Author: Hesbon Osoro
Date: 12/10/22
Filename: ah_report.js
Functions:
calcSum(donorAmt)
A callback function that adds the current donation amount in the array to the donationTotal variable
findMajorDonors(donorAmt)
A callback function that returns the value true only if the current donation amount in the array
is greater than or equal to 1000
donorSortDescending(a, b)
A callback function used to sort the donation amounts from the array in descending order
writeDonorRow(value)
A callback function that writes the HTML code for each table row that provides the contact
information for the donor
*/
/* Variables */
var donationTotal = 0;
donors.forEach(calcSum);
var summaryTable =
"<table>" +
"<tr><th>Donors</th><td>" +
donors.length +
"</td></tr>" +
"<tr><th>Total Donations</th><td>$" +
donationTotal.toLocaleString() +
"</td></tr>" +
"</table>";
document.getElementById("donationSummary").innerHTML = summaryTable;
/* Major donors */
var majorDonors = donors.filter(findMajorDonors);
majorDonors.sort(donorSortDescending);
var donorTable =
"<table>" +
"<caption>Major Donors</caption>" +
"<tr>" +
"<th>Donation</th>" +
"<th>Donor ID</th>" +
"<th>Date</th>" +
"<th>Name</th>" +
"<th>Address</th>" +
"<th>Phone</th>" +
"<th>E-mail</th>" +
"</tr>";
majorDonors.forEach(writeDonorRow);
donorTable += "</table>";
document.getElementById("donorTable").innerHTML = donorTable;
function calcSum(donorAmt) {
donationTotal += donorAmt[9];
}
function findMajorDonors(donorAmt) {
return donorAmt[9] >= 1000;
}
function donorSortDescending(a, b) {
return b[9] - a[9];
}
function writeDonorRow(value) {
donorTable += "<tr>";
donorTable += "<td>$" + value[9].toLocaleString() + "</td>";
donorTable += "<td>" + value[0] + "</td>";
donorTable += "<td>" + value[10] + "</td>";
donorTable += "<td>" + value[2] + ", " + value[1] + "</td>";
donorTable +=
"<td>" +
value[3] +
"<br />" +
value[4] +
", " +
value[5] +
" " +
value[6] +
"</td>";
donorTable += "<td>" + value[7] + "</td>";
donorTable += "<td>" + value[8] + "</td>";
donorTable += "</tr>";
}