EDIT: I've included my more code for clarity I've created a table using a constructor function to create multiple table bodies, but I don't want the header and footer repeated so I've created those separately. However, one the properties of the created is an empty array that gets filled. I can't currently access it.
function Store(storeId, minCustomer, maxCustomer, avgSale) {
this.storeId = storeId;
this.minCustomer = minCustomer;
this.maxCustomer = maxCustomer;
this.avgSale = avgSale;
this.arrCookie = [];
this.addDom();
};
Store.prototype.addDom = function() {
this.cookiesPerHour();
var findTable = document.getElementById('table');
var tBody = document.createElement('tbody');
var trtBody = document.createElement('tr');
var tdstoreId = document.createElement('td');
tdstoreId.innerHTML = this.storeId;
findTable.appendChild(tBody);
tBody.appendChild(trtBody);
trtBody.appendChild(tdstoreId);
var totalStoreCookies = 0;
for (var i = 0; i < this.arrCookie.length; i++) {
var info1 = document.createElement('td');
info1.innerHTML = this.arrCookie[i];
trtBody.appendChild(info1);
};
for (var i = 0; i < this.arrCookie.length; i++) {
totalStoreCookies += this.arrCookie[i];
};
var info2 = document.createElement('td');
info2.innerHTML = totalStoreCookies;
trtBody.appendChild(info2);
};
function makeTHF() {
var totalCookies = 0;
var findTable = document.getElementById('table');
var tHead = document.createElement('thead');
var trtHead = document.createElement('tr');
var findTable = document.getElementById('table');
var tFoot = document.createElement('tfoot');
var trtFoot = document.createElement('tr');
var hourlyTotal = document.createElement('td');
findTable.appendChild(tHead);
tHead.appendChild(trtHead);
findTable.appendChild(tFoot);
tFoot.appendChild(trtFoot);
for (var i = 0; i < 17; i++) {
var time = document.createElement('th');
time.innerHTML = arrTime[i];
trtHead.appendChild(time);
};
for (var i = 0; i < arrCookie.length; i++) {
var storeName = [PDXAirport, PioneerSquare, Powells, StJohns, Waterfront];
hourlyTotal.innerHTML = 'Total';
var colTotal = 0;
for (var j = 0; j < storeName.length; j++) {
colTotal += storeName[j].arrCookie[i];
hourlyTotal.innerHTML = colTotal;
};
trtFoot.appendChild(hourlyTotal);
console.log(storeName);
};
};
var PDXAirport = new Store('PDX Airport', 23, 65, 6.3);
var PioneerSquare = new Store('Pioneer Square', 3, 24, 1.2);
var Powells = new Store('Powell\'s', 11, 38, 3.7);
var StJohns = new Store('St. John\'s', 20, 38, 2.3);
var Waterfront = new Store('Waterfront', 2, 16, 4.6);
makeTHF();
When I try use arrCookie during the makeTHF function I get an error saying undefined when I try to use arrCookies.length as an instruction for the "for" loop. placing "this." before it doesn't change the outcome. I can't think of any reasons why this wouldn't work. The array is being properly populated during the prototype function. I've deleted some of the code not relevant to the problem for brevity.