Question
The donor table doesn't display correctly for this code and I think it's related to the direction to Apply the forEach() method to the
The donor table doesn't display correctly for this code and I think it's related to the direction to " Apply the forEach() method to the donors array, using the callback function calcSum(). This statement will calculate the donation total." in my code, but I can't be sure. this is javascript. Directions must be followed exactly - no creative changes are allowed.
this is the directions
Variables
Create a variable named donationTotal in which you will calculate the total amount of the donations to Appalachian House. Set its initial value to 0.
Apply the forEach() method to the donors array, using the callback function calcSum(). This statement will calculate the donation total.
Create a variable named summaryTable storing the text of the following HTML code
Donors | donors |
---|---|
Total Donations | $total |
where donors is the length of the donors array, and total is the value of the donationTotal variable, preceded by a $. Apply the toLocaleString() method to the donationTotal variable so that the total amount of donations is displayed with a thousands separator in the report.
Set the innerHTMLproperty of the div element with the ID donationSummary to the value of the summaryTable variable.
IMIPORTANT NOTE: donors is a multidimensional array. The amount of each donation is stored in the tenth column (index 9). **This is what needs to be passed to calc sum of the donationTotal variable, preceded by a $. Apply the toLocaleString() method to the donationTotal variable so that the total amount of donations is displayed with a thousands separator in the report.
Set the innerHTMLproperty of the div element with the ID donationSummary to the value of the summaryTable variable.
Here's what I've tried so far
- I added the script elements to the HTML file head names are spelled correctly
- I added the two div elements below the h1 heading just above the end of the section and again I checked spelling
- I double checked all the variable names in my script, made sure the statements had a closing ; ( but since each of these passed validation, I dont know what I should be looking at for the error)
My script from ah_report.js page (directions above)
var donationTotal = 0;
donors.forEach(calcSum); *****MIGHT BE THE PROBLEM BUT I HAVE NO IDEA see other variations I've tried in the following commented out section
/*for(var i = 9; i
{
donors.forEach(calcSum);
}
*/
/* also tried this but it doesn't work
donors.forEach(calcSum);
*/
/*tried this as well - doesn't work
calcSum(donors.foreach());
*/
var summaryTable = "
";Donors " + donors.length +" Total Donations $" + donationTotal.tolocalestring(en) + "
document.getElementByID("donationSummary").innerHTML = summaryTable;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started