Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My Javascript code does not work correctly, table does not display. I've pasted in the step by step instructions given to create teh code followed

My Javascript code does not work correctly, table does not display. I've pasted in the step by step instructions given to create teh code followed by my code from the ah_report.js file. I have double checked all variable name spellings.

***************************DIRECTIONS****************************************

Open the ah_donors.js file. Study the content of the multidimensional array named donors. Note that the first column of the array (with an index of 0) contains the ID of each donor, the second column (index 1) contains the donors first name, the third column (index 2) contains the donors last name, and so forth. The amount of each donation is stored in the tenth column (index 9). Do not make any changes to the content of this file.

Next go to the ah_report.js file. The file contains four callback functions at the end of the file that you will use in generating the donation report. Take some time to study the content of these functions.

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 totalis 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 summaryTablevariable

**********ah_donors.js file. Study the content of the multidimensional array named donors (including schema only - contents not need here for solving problem *************

/*Filename: ah_product.js Variables: the donors multi-dimension array contains the following data with following column indices donors[0] - donorID donors[1] - frist name donors[2] - last name donors[3] - address donors[4] - city donors[5] - state donors[6] - postal code donors[7] - phone number donors[8] - email donors[9] - donation amount donors[10] - donation date */

*********************** MY CODE ***********************

"use strict";

/* Filename: ah_report.js Description of Functions already provided as part of assignment include in this file: 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 */

/* MY CODE IS NEXT FOUR LINES THAT CORRESPOND TO THE DIRECTIONS */

var donationTotal = 0;

donors.foreach(calcSum);

var summaryTable = "

Donors" +donors.length + "
Total Donations$" + donationTotal.toLocaleString(+"'en-us'"+) + "
";

document.getElementById("donationSummary").innerHTML = summaryTable;

/* FUNCTIONS PROVIDED AS PART OF ASSIGNMENT */ 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 += ""; donorTable += "$" + value[9].toLocaleString() + ""; donorTable += "" + value[0] + ""; donorTable += "" + value[10] + ""; donorTable += "" + value[2] + ", " + value[1] + ""; donorTable += "" + value[3] + "
" + value[4] + ", " + value[5] + " " + value[6] + ""; donorTable += "" + value[7] + ""; donorTable += "" + value[8] + ""; donorTable += ""; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions