<commit_before>var hours = ['10 am', '11 am', '12 pm', '1 pm', '2 pm', '3 pm', '4 pm', '5 pm'];
var tableEl = document.getElementById('myStores');

function Store(storeName, minCust, maxCust, avgCookie) {
  this.storeName = storeName;
  this.minCust = minCust;
  this.maxCust = maxCust;
  this.avgCookie = avgCookie;
  this.totalDemand = 0;
  this.demands = [];
}

Store.prototype.generateRandom = function(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
};

Store.prototype.hourlyDemand = function(hrArr, dmndArr, rand, min, max, avg, total) {
  for(hour in hrArr) {
    dmndArr.push(Math.floor(rand(min, max) * avg));
    total += dmndArr[hour];
  }
  return total;
};


(Store.renderTable = function() {
  // Create a table element using the global var `tbl` and assign it an id attribute

  // Create your first row and empty `th` for the hours, and put them together
  var trHeader = document.createElement('tr');
  var thEmpty = document.createElement('th');
  trHeader.appendChild(thEmpty);

  for(idx in hours) {
    var thEl = document.createElement('th');
    thEl.textContent = hours[idx];
    trHeader.appendChild(thEl);
  }

  var thTotals = document.createElement('th');
  thTotals.textContent = 'Totals';
  trHeader.appendChild(thTotals);
  tableEl.appendChild(trHeader);
  // Step into a for loop and populate your times in that first row
  // Finish the first row with a `th` for Totals, and append everything to the table
  // Notice that this is inside an IIFE... It will run on page load and set up the table every time.
  // You do not have access to this method in the global scope.
})();

//This is from last assignment with lists

// Store.prototype.render = function() {
//   this.totalDemand = this.hourlyDemand(hours, this.demands, this.generateRandom, this.minCust, this.maxCust, this.avgCookie, this.totalDemand);
//
//   var sectionEl = document.getElementById('stores');
//   var newStoreSection = document.createElement('section');
//   newStoreSection.textContent = this.storeName;
//   sectionEl.appendChild(newStoreSection);
//   var ulEl = document.createElement('ul');
// //This creates li for each hour and appends it to the ul we created above
//   for(hour in hours) {
//     var liEl = document.createElement('li');
//     liEl.textContent = hours[hour] + ': ' + this.demands[hour];
//     ulEl.appendChild(liEl);
//   }
// //This creates and li for totalDemand and appends it to the ul created above
// //then appends it to the existing section within our HTML.
//   liEl = document.createElement('li');
//   liEl.textContent = 'Total: ' + this.totalDemand;
//   ulEl.appendChild(liEl);
//   sectionEl.appendChild(ulEl);
// };

var pikePlace = new Store('Pike Place', 17, 88, 5.2);
var seaTacAirport = new Store('SeaTac Airport', 6, 24, 1.2);
var southcenter = new Store('Souchcenter', 11, 38, 1.9);
var bellevueSquare = new Store('Bellevue Square', 20, 48, 3.3);
var alki = new Store('Alki', 3, 24, 2.6);

// var stores = [pikePlace, seaTacAirport, southcenter, bellevueSquare, alki];
// for(idx in stores) {
//   stores[idx].render();
// }
<commit_msg>Table is printing with all sales data and totals<commit_after>var hours = ['10 am', '11 am', '12 pm', '1 pm', '2 pm', '3 pm', '4 pm', '5 pm'];
var tableEl = document.getElementById('myStores');
var shops = [];

function Store(storeName, minCust, maxCust, avgCookie) {
  this.storeName = storeName;
  this.minCust = minCust;
  this.maxCust = maxCust;
  this.avgCookie = avgCookie;
  this.totalDemand = 0;
  this.demands = [];
  shops.push(this);
}

Store.prototype.generateRandom = function(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
};

Store.prototype.hourlyDemand = function() {
  for (hour in hours) {
    this.demands.push(Math.floor(this.generateRandom(this.minCust, this.maxCust) * this.avgCookie));
    this.totalDemand += this.demands[hour];
  };
};

var pikePlace = new Store('Pike Place', 17, 88, 5.2);
var seaTacAirport = new Store('SeaTac Airport', 6, 24, 1.2);
var southcenter = new Store('Souchcenter', 11, 38, 1.9);
var bellevueSquare = new Store('Bellevue Square', 20, 48, 3.3);
var alki = new Store('Alki', 3, 24, 2.6);

(Store.renderTable = function() {
  var trHeader = document.createElement('tr');
  var thEmpty = document.createElement('th');
  trHeader.appendChild(thEmpty);

  for(idx in hours) {
    var thEl = document.createElement('th');
    thEl.textContent = hours[idx];
    trHeader.appendChild(thEl);
  }

  var thTotals = document.createElement('th');
  thTotals.textContent = 'Totals';
  trHeader.appendChild(thTotals);
  tableEl.appendChild(trHeader);

  for (idx in shops) {
    shops[idx].hourlyDemand();

    var trStoreEl = document.createElement('tr');
    var thStoreEl = document.createElement('th');
    thStoreEl.textContent = shops[idx].storeName;
    trStoreEl.appendChild(thStoreEl);

    for (hour in hours) {
      var tdSalesEl = document.createElement('td');
      tdSalesEl.textContent = shops[idx].demands[hour];
      trStoreEl.appendChild(tdSalesEl);
    }

    var tdTotalSalesEl = document.createElement('td');
    tdTotalSalesEl.textContent = shops[idx].totalDemand;
    trStoreEl.appendChild(tdTotalSalesEl);
    tableEl.appendChild(trStoreEl);
  };
})();

// Store.renderNew = function(name, minimum, maximum, average) {
//   var newStore = new Store(name, minimum, maximum, average);
//   // Use that global variable for `tbl` and target it's id (remember when you created it and set the id?)
//   // Create a new instance of a store object using the parameters available in this method.
// };
//
// document.getElementById('new-store').addEventListener('submit', function(event) {
//   // Add an event listener to the form in our HTML
  // Prevent the default behavior of the form submit
  // NOTE: Stretch goal item; You need something to determine whether the store exists already in the table... perhaps a boolean?
  // Assign the values of each input field to variables for later used
  // NOTE: Stretch goal item: Iterate over your shops array to determine whether the inputs relate to a store that's already been created
    // If so, you probably want to do something with that boolean value...
  // NOTE: Stretch goal item: If the store exists, run the renderUpdate and pass in arguments to complete the call
    // Otherwise, just take your new values and run the renderNew method
  // Finally, set each of the values of your inputs to `null`

{'fraction_non_alphanumeric': 0.1349218629119604, 'fraction_numerical': 0.01268760637474857, 'mean_word_length': 3.8131049888309754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3757871', 'n_tokens_mistral': 2109, 'n_tokens_neox': 2013, 'n_words': 647}