Как исправить проблему с пушем? [закрыто]

Когда я нажимаю кнопку «Отправить» в форме, предполагается, что значения будут отправлены в мой объект (Storelocation), а при выполнении функции предполагается добавить новую форму из данных, затем добавить строки и заполнить таблицу данными из формы.. но он даже не переносит данные в глобальный массив.

      let workingHours=['6am','7am','8am','9am','10am', '11am','12pm','1pm','2pm','3pm','4pm','5pm','6pm','7pm'];
let locationGloblal=[];

console.log(locationGloblal);

function getRandomIntInclusive(min, max) {
  return (Math.floor(Math.random() * (max - min + 1) + min));
}


function Storelocation(location,minCustomer,maxCustomer,AvgCookiePerSale)
{
  this.location=location;
  this.minCustomer=minCustomer;
  this.maxCustomer=maxCustomer;
  this.AvgCookiePerSale=AvgCookiePerSale;
  this.totalCookiesPerDay=0;
  this.randomNumberCustomersPerHour=[];
  this.avgSalePerHour=[];
  locationGloblal.push(this);

}

Storelocation.prototype.getRandomCustomer= function()
{
  for (let i=0;i<workingHours.length;i++){
    let randomCustomer = getRandomIntInclusive(this.minCustomer,this.maxCustomer);
    this.randomNumberCustomersPerHour.push(randomCustomer);
  }};


Storelocation.prototype.calSalePerHour=function(){
  for (let i=0;i<workingHours.length;i++){
    const amountSoldPerHour= Math.ceil(this.AvgCookiePerSale*this.randomNumberCustomersPerHour[i]);
    this.avgSalePerHour.push(amountSoldPerHour);
    this.totalCookiesPerDay=this.totalCookiesPerDay+amountSoldPerHour;}
};


// Form elements

let storeform=document.getElementById('storeform');
let formsection=document.getElementById('formsection');
formsection.appendChild(storeform);

storeform.addEventListener('submit', addNewBranch);
function addNewBranch(event)

{
  let locationnew=event.target.locationnew.value;
  event.preventDefault();
  console.log(locationnew);

  let mincust=event.target.mincust.value;
  event.preventDefault();
  console.log(mincust);

  let maxcust=event.target.maxcust.value;
  event.preventDefault();
  console.log(maxcust);

  let avgsale=event.target.avgsale.value;
  event.preventDefault();
  console.log(avgsale);

  const newlocation= new Storelocation(locationnew,mincust,maxcust,avgsale);
  newlocation.getRandomCustomer();
  newlocation.calSalePerHour();
  console.log(newlocation);
  return false;


}












const Seattle= new Storelocation('Seattle',23,65,6.3);
const Tokyo= new Storelocation('Tokyo',3,24,1.2);
const Dubai= new Storelocation('Dubai',11,38,3.7);
const Paris= new Storelocation('Paris',20,38,2.3);
const Lima= new Storelocation('Lima',2,16,4.6);

// // console.log(Seattle);
Seattle.getRandomCustomer();
Seattle.calSalePerHour();


// // console.log(Tokyo);
Tokyo.getRandomCustomer();
Tokyo.calSalePerHour();


// console.log(Dubai);
Dubai.getRandomCustomer();
Dubai.calSalePerHour();


// console.log(Paris);
Paris.getRandomCustomer();
Paris.calSalePerHour();

// console.log(Lima);
Lima.getRandomCustomer();
Lima.calSalePerHour();







let theParent=document.getElementById('tableplace');
let tableEL=document.createElement('table');
theParent.appendChild(tableEL);


//header
function header(){
  let headerEL=document.createElement('tr');
  tableEL.appendChild(headerEL);

  let headerData=document.createElement('th');
  headerEL.appendChild(headerData);
  headerData.textContent='Location';


  for (let i=0;i<workingHours.length;i++){
    let headerData=document.createElement('th');
    headerEL.appendChild(headerData);
    headerData.textContent=`${workingHours[i]}`;
  }

  let headerTotal=document.createElement('th');
  headerEL.appendChild(headerTotal);
  headerTotal.textContent='Daily location total';



}
header();



//inner
function innerData(){

  for(let i=0;i<locationGloblal.length;i++){
    let newRows=document.createElement('tr');
    tableEL.appendChild(newRows);

    for(let j=0;j<workingHours.length+2;j++){

      if (j===0){
        let newCells=document.createElement('td');
        newRows.appendChild(newCells);
        newCells.textContent=locationGloblal[i].location;
      } else if (j<15){
        let newCells=document.createElement('td');
        newRows.appendChild(newCells);
        newCells.textContent=locationGloblal[i].avgSalePerHour[j-1];
      } else if (j===15){
        let newCells=document.createElement('td');
        newRows.appendChild(newCells);
        newCells.textContent=locationGloblal[i].totalCookiesPerDay;
      }
    }



  }
}

innerData();




//the footer
function footer(){
  // let newlocationEL=document.createElement('tr');
  // tableEL.appendChild(newlocationEL);
  // let newlocationData=document.createElement('th');
  // newlocationEL.appendChild(newlocationData);
  // newlocationData.textContent=locationGloblal[5].location;


  let footerEL=document.createElement('tr');
  tableEL.appendChild(footerEL);
  let footerData=document.createElement('th');
  footerEL.appendChild(footerData);
  footerData.textContent='Totals';


  let total=0;
  let sum=0;
  for (let i=0;i<workingHours.length; i++){

    for(let j=0;j<locationGloblal.length;j++){
      sum=sum+locationGloblal[j].avgSalePerHour[i];
    }
    let footerData=document.createElement('th');
    footerEL.appendChild(footerData);
    footerData.textContent=sum;
    total=total+sum;
    sum=0;

  }

  for(let i=0;i<workingHours.length+2;i++){
    if (i===15){
      let footerData=document.createElement('th');
      footerEL.appendChild(footerData);
      footerData.textContent=total;}

  }
}
footer();
console.log(locationGloblal);

0 ответов

Другие вопросы по тегам