<commit_before>'use strict';

console.log('-------------------------Constructor-------------------');
//costructors have capitolized first letter, upper camel case;
var storeHours = ['6am', '7am', '8am', '9am', '10am', '11am', '12pm', '1pm', '2pm', '3pm', '4pm', '5pm', '6pm', '7pm', '8pm'];

function CookieStore(name, minCustomers, maxCustomers, avgCookies, hourlyCookies, dailyTotals){
  this.name = name;
  this.minCustomers = minCustomers;
  this.maxCustomers = maxCustomers;
  this.avgCookies = avgCookies;
  this.hourlyCookies = [];
  this.dailyTotals = 0;
}
//calc random number
CookieStore.prototype.cookiesHour = function() {
  return(Math.floor(Math.random() * (this.maxCustomers - this.minCustomers) + this.minCustomers));
};
//creating an array for all times
CookieStore.prototype.cookiesEachHour = function(){
  for(var i = 0; i < storeHours.length; i++){
    var sales = Math.floor(this.cookiesHour() * this.avgCookies);
    this.hourlyCookies.push(sales);
    this.dailyTotals += sales;
  }
};
//add method to CookieStore that adds rows for each store
CookieStore.prototype.createRow = function(){
  this.cookiesEachHour();
  var storeRowEl = document.createElement('tr');
  salesTable.appendChild(storeRowEl);

  var storeNameEl = document.createElement('th');
  storeNameEl.textContent = this.name;
  storeRowEl.appendChild(storeNameEl);
  console.log('got here 1');
  for(var i = 0; i < this.hourlyCookies.length; i++){
    console.log('got here 2');
    var hourlySalesEl = document.createElement('td');
    hourlySalesEl.textContent = this.hourlyCookies[i];
    storeRowEl.appendChild(hourlySalesEl);

  }
  var dailyTotalEl = document.createElement('td');
  dailyTotalEl.textContent = this.dailyTotals;
  storeRowEl.appendChild(dailyTotalEl);

};

var pikePlace = new CookieStore('Pike Place', 23, 65, 6.3);
var seaTac = new CookieStore('SeaTac Airport', 3, 24, 1.2);
var seattleCenter = new CookieStore('Seattle Center', 11, 38, 3.7);
var capitolHill = new CookieStore('Capitol Hill', 20, 38, 2.3);
var alki = new CookieStore('Alki', 2, 16, 4.6);

var stores = [pikePlace, seaTac, seattleCenter, capitolHill, alki];
//make table

var salesTable = document.getElementById('table');
function createToplabelRow(){
  var labelRowEl = document.createElement('tr');
  salesTable.appendChild(labelRowEl);

  var rowHeaderEmptyEl = document.createElement('th');
  rowHeaderEmptyEl.textContent = 'Hours';
  labelRowEl.appendChild(rowHeaderEmptyEl);

  for(var i = 0; i < storeHours.length; i++ ){
    var hourOpenEl = document.createElement('th');
    hourOpenEl.textContent = storeHours[i];
    labelRowEl.appendChild(hourOpenEl);
  }
  var dailyTotalHeaderEl = document.createElement('td');
  dailyTotalHeaderEl.textContent = 'Daily Totals';
  labelRowEl.appendChild(dailyTotalHeaderEl);
}
function createAllRows() {
  for(var i = 0; i < stores.length; i++){
    stores[i].createRow();
    console.log(stores[i].cookiesEachHour);
  }
}

createToplabelRow();
createAllRows();

console.log('-----------------Event Listeners--------------------');

//get access to form from the DOM
var storeFormEl = document.getElementById('new-store-form');

storeFormEl.addEventListener('submit', handleSubmit);
//press submit runs function handleSubmit, false prevents event capturing

function handleSubmit(event){
  event.preventDefault(); //prevents page from reloading/send to server
  event.stopPropagation();//prevents click event on parent tags

  var storeName = event.target.cookieStoreName.value;// event=eventlistener, target=target node"storeFormEl", cookieStoreNeme node within target node, value is input of node
  var minCustomers = parseInt(event.target.minCust.value); //gets minCust value, parseInt prevents input of string
  var maxCustomers = parseInt(event.target.maxCust.value);
  var avgCookies = parseInt(event.target.avgCookies.value);

  // console.log(storeName);
  // console.log(minCustomers);
  // console.log(maxCustomers);
  // console.log(avgCookies);

  var addedStore = new CookieStore(storeName, minCustomers, maxCustomers, avgCookies);
  // console.log(store);
  addedStore.createRow();
  console.log(stores);
  console.log(addedStore);
  console.log('User Pressed Subit on Form!');
}<commit_msg>add row wroking coorectly<commit_after>'use strict';

var pikePlace = new CookieStore('Pike Place', 23, 65, 6.3);
var seaTac = new CookieStore('SeaTac Airport', 3, 24, 1.2);
var seattleCenter = new CookieStore('Seattle Center', 11, 38, 3.7);
var capitolHill = new CookieStore('Capitol Hill', 20, 38, 2.3);
var alki = new CookieStore('Alki', 2, 16, 4.6);

var stores = [pikePlace, seaTac, seattleCenter, capitolHill, alki];
var storeHours = ['6am', '7am', '8am', '9am', '10am', '11am', '12pm', '1pm', '2pm', '3pm', '4pm', '5pm', '6pm', '7pm', '8pm'];

console.log('-------------------------Constructor-------------------');
//costructors have capitolized first letter, upper camel case;

function CookieStore(name, minCustomers, maxCustomers, avgCookies, hourlyCookies, dailyTotals){
  this.name = name;
  this.minCustomers = minCustomers;
  this.maxCustomers = maxCustomers;
  this.avgCookies = avgCookies;
  this.hourlyCookies = [];
  this.dailyTotals = 0;
}
//calc random number
CookieStore.prototype.cookiesHour = function() {
  return(Math.floor(Math.random() * (this.maxCustomers - this.minCustomers) + this.minCustomers));
};
//creating an array for all times
CookieStore.prototype.cookiesEachHour = function(){
  for(var i = 0; i < storeHours.length; i++){
    var sales = Math.floor(this.cookiesHour() * this.avgCookies);
    this.hourlyCookies.push(sales);
    this.dailyTotals += sales;
  }
};

//add method to CookieStore that adds rows for each store
CookieStore.prototype.createRow = function(){
  this.cookiesEachHour();
  var storeRowEl = document.createElement('tr');
  salesTable.appendChild(storeRowEl);

  var storeNameEl = document.createElement('th');
  storeNameEl.textContent = this.name;
  storeRowEl.appendChild(storeNameEl);
  console.log('got here 1');
  for(var i = 0; i < this.hourlyCookies.length; i++){
    console.log('got here 2');
    var hourlySalesEl = document.createElement('td');
    hourlySalesEl.textContent = this.hourlyCookies[i];
    storeRowEl.appendChild(hourlySalesEl);

  }
  var dailyTotalEl = document.createElement('td');
  dailyTotalEl.textContent = this.dailyTotals;
  storeRowEl.appendChild(dailyTotalEl);

};

var salesTable = document.getElementById('table');
function createToplabelRow(){
  var labelRowEl = document.createElement('tr');
  salesTable.appendChild(labelRowEl);

  var rowHeaderEmptyEl = document.createElement('th');
  rowHeaderEmptyEl.textContent = 'Hours';
  labelRowEl.appendChild(rowHeaderEmptyEl);

  for(var i = 0; i < storeHours.length; i++ ){
    var hourOpenEl = document.createElement('th');
    hourOpenEl.textContent = storeHours[i];
    labelRowEl.appendChild(hourOpenEl);
  }
  var dailyTotalHeaderEl = document.createElement('td');
  dailyTotalHeaderEl.textContent = 'Daily Totals';
  labelRowEl.appendChild(dailyTotalHeaderEl);
}
function createAllRows() {
  for(var i = 0; i < stores.length; i++){
    stores[i].createRow();
  }
}

createToplabelRow();
createAllRows();

console.log('-----------------Event Listeners--------------------');

//get access to form from the DOM
var storeFormEl = document.getElementById('new-store-form');

storeFormEl.addEventListener('submit', handleSubmit);
//press submit runs function handleSubmit, false prevents event capturing

function handleSubmit(event){
  event.preventDefault(); //prevents page from reloading/send to server
  event.stopPropagation();//prevents click event on parent tags

  var storeName = event.target.cookieStoreName.value;// event=eventlistener, target=target node"storeFormEl", cookieStoreNeme node within target node, value is input of node
  var minCustomers = parseInt(event.target.minCust.value); //gets minCust value, parseInt prevents input of string
  var maxCustomers = parseInt(event.target.maxCust.value);
  var avgCookies = parseInt(event.target.avgCookies.value);

  // console.log(storeName);
  // console.log(minCustomers);
  // console.log(maxCustomers);
  // console.log(avgCookies);

  var addedStore = new CookieStore(storeName, minCustomers, maxCustomers, avgCookies);
  // console.log(store);
  addedStore.createRow();
  console.log(stores);
  console.log('User Pressed Subit on Form!');
  stores.push(addedStore);
}
{'fraction_non_alphanumeric': 0.15325261158594491, 'fraction_numerical': 0.01258309591642925, 'mean_word_length': 4.63168449197861, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2776935', 'n_tokens_mistral': 2779, 'n_tokens_neox': 2625, 'n_words': 616}