<reponame>AustinJBrown1/cookie-stand<filename>js/app.js
var hoursArray = [' 6 am  || ',' 7 am || ',' 8 am || ',' 9 am || ',' 10 am || ',' 11 am || ',' 12 pm || ',' 1 pm || ',' 2 pm || ',' 3 pm || ',' 4 pm || ',' 5 pm || ',' 6 pm || ',' 7 pm || ',' 8 pm || '];
function getRandomIntInclusive(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var seattle = {
  cityName: 'Seattle',
  customerMax: 65,
  customerMin: 23,
  avg: 6.3,
  cookiesPerHourArray: [],
  custPerHourArray: [],
  //All objects contain a version of this function, it creates the on-screen lists and populates them with the appropriate values
  render: function(){
    var salesData = document.getElementById('salesData');
    var timeLists = document.createElement('ul');
    timeLists.textContent =this.cityName;
    for(var i = 0; i < hoursArray.length; i++){
      var timeOfDay = document.createElement('li');
      timeOfDay.textContent = `${hoursArray[i]}${this.cookiesPerHourArray[i]}`;
      timeLists.appendChild(timeOfDay);
    }
    salesData.appendChild(timeLists);
    //This block of code adds a list item that displays the total amount of cookies bought over the course of the day. It is populated by the "totalCookies" method.
    var total = document.createElement('li');

    total.textContent = 'Total || ' + this.totalCookies();

    timeLists.appendChild(total);
  },
  custPerHour: function(){
    console.log('seattle: customers');
    //This 'for' loop fills the custPerHourArray with randomly generated values based on the given statistics.
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCust generates random numbers for the associated array
      var randomCust = Math.floor(Math.random()*(this.customerMax - this.customerMin ) + this.customerMin);
      //Pushes the values generated by randomCust into the array
      this.custPerHourArray.push(randomCust);
      //This displays the values in the browser console
      console.log(this.custPerHourArray);
    }
  },
  cookiesPerHour: function(){
    console.log('seattle: cookies');
    //This 'for' loop fills the cookiesPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCookie generates random numbers for the associated array
      var randomCookie = Math.floor(getRandomIntInclusive(this.customerMin, this.customerMax) * this.avg);
      //Pushes the values generated by randomCookie into the array
      this.cookiesPerHourArray.push(randomCookie);
      //This displays the values in the browser console
      console.log(this.cookiesPerHourArray);
    }
  },
  totalCookies: function(){
    var totalAmount = 0;
    for(var i=0; i < this.cookiesPerHourArray.length; i++){
      totalAmount += this.cookiesPerHourArray[i];
      // this.totalCookiesArray.push(totalAmount);
    }
    return totalAmount;
  }
};
seattle.custPerHour();
seattle.cookiesPerHour();
seattle.totalCookies();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var tokyo = {
  cityName: 'Tokyo',
  customerMax: 24,
  customerMin: 3,
  avg: 1.2,
  cookiesPerHourArray: [],
  custPerHourArray: [],
  render: function(){
    var salesData = document.getElementById('salesData');
    var timeLists = document.createElement('ul');
    timeLists.textContent =this.cityName;
    for(var i = 0; i < hoursArray.length; i++){
      var timeOfDay = document.createElement('li');
      timeOfDay.textContent = `${hoursArray[i]}${this.cookiesPerHourArray[i]}` ;
      timeLists.appendChild(timeOfDay);
    }
    salesData.appendChild(timeLists);
    var total = document.createElement('li');

    total.textContent = 'Total || ' + this.totalCookies();


    timeLists.appendChild(total);
  },
  custPerHour: function(){
    console.log('tokyo: customers');
    //This 'for' loop fills the custPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCust generates random numbers for the associated array
      var randomCust = Math.floor(Math.random()*(this.customerMax - this.customerMin ) + this.customerMin);
      //Pushes the values generated by randomCust into the array
      this.custPerHourArray.push(randomCust);
      //This displays the values in the browser console
      console.log(this.custPerHourArray);
    }
  },
  cookiesPerHour: function(){
    console.log('tokyo: cookies');
    //This 'for' loop fills the cookiesPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCookie generates random numbers for the associated array
      var randomCookie = Math.floor((Math.random()*(this.customerMax - this.customerMin) + this.customerMin) * this.avg);
      //Pushes the values generated by randomCookie into the array
      this.cookiesPerHourArray.push(randomCookie);
      //This displays the values in the browser console
      console.log(this.cookiesPerHourArray);
    }
  },
  totalCookies: function(){
    var totalAmount = 0;
    for(var i=0; i < this.cookiesPerHourArray.length; i++){
      totalAmount += this.cookiesPerHourArray[i];
    }
    return totalAmount;
  },
};
tokyo.custPerHour();
tokyo.cookiesPerHour();
tokyo.totalCookies();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var dubai = {
  cityName: 'Dubai',
  customerMax: 38,
  customerMin: 11,
  avg: 3.7,
  cookiesPerHourArray: [],
  custPerHourArray: [],
  render: function(){
    var salesData = document.getElementById('salesData');
    var timeLists = document.createElement('ul');
    timeLists.textContent =this.cityName;
    for(var i = 0; i < hoursArray.length; i++){
      var timeOfDay = document.createElement('li');
      timeOfDay.textContent = `${hoursArray[i]}${this.cookiesPerHourArray[i]}` ;
      timeLists.appendChild(timeOfDay);
    }
    salesData.appendChild(timeLists);
    var total = document.createElement('li');

    total.textContent = 'Total || ' + this.totalCookies();

    timeLists.appendChild(total);
  },
  custPerHour: function(){
    console.log('dubai: customers');
    //This 'for' loop fills the custPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCust generates random numbers for the associated array
      var randomCust = Math.floor(Math.random()*(this.customerMax - this.customerMin ) + this.customerMin);
      //Pushes the values generated by randomCust into the array
      this.custPerHourArray.push(randomCust);
      //This displays the values in the browser console
      console.log(this.custPerHourArray);
    }
  },
  cookiesPerHour: function(){
    console.log('dubai: cookies');
    //This 'for' loop fills the cookiesPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCookie generates random numbers for the associated array
      var randomCookie = Math.floor((Math.random()*(this.customerMax - this.customerMin) + this.customerMin) * this.avg);
      //Pushes the values generated by randomCookie into the array
      this.cookiesPerHourArray.push(randomCookie);
      //This displays the values in the browser console
      console.log(this.cookiesPerHourArray);
    }
  },
  totalCookies: function(){
    var totalAmount = 0;
    for(var i=0; i < this.cookiesPerHourArray.length; i++){
      totalAmount += this.cookiesPerHourArray[i];
    }
    return totalAmount;
  },
};
dubai.custPerHour();
dubai.cookiesPerHour();
dubai.totalCookies();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var paris = {
  cityName: 'Paris',
  customerMax: 38,
  customerMin: 20,
  avg: 2.3,
  cookiesPerHourArray: [],
  custPerHourArray: [],
  render: function(){
    var salesData = document.getElementById('salesData');
    var timeLists = document.createElement('ul');
    timeLists.textContent =this.cityName;
    for(var i = 0; i < hoursArray.length; i++){
      var timeOfDay = document.createElement('li');
      timeOfDay.textContent = `${hoursArray[i]}${this.cookiesPerHourArray[i]}` ;
      timeLists.appendChild(timeOfDay);
    }
    salesData.appendChild(timeLists);
    var total = document.createElement('li');

    total.textContent = 'Total || ' + this.totalCookies();

    timeLists.appendChild(total);
  },
  custPerHour: function(){
    console.log('paris: customers');
    //This 'for' loop fills the custPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCust generates random numbers for the associated array
      var randomCust = Math.floor(Math.random()*(this.customerMax - this.customerMin ) + this.customerMin);
      //Pushes the values generated by randomCust into the array
      this.custPerHourArray.push(randomCust);
      //This displays the values in the browser console
      console.log(this.custPerHourArray);
    }
  },
  cookiesPerHour: function(){
    console.log('paris: cookies');
    //This 'for' loop fills the cookiesPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCookie generates random numbers for the associated array
      var randomCookie = Math.floor((Math.random()*(this.customerMax - this.customerMin) + this.customerMin) * this.avg);
      //Pushes the values generated by randomCookie into the array
      this.cookiesPerHourArray.push(randomCookie);
      //This displays the values in the browser console
      console.log(this.cookiesPerHourArray);
    }
  },
  totalCookies: function(){
    var totalAmount = 0;
    for(var i=0; i < this.cookiesPerHourArray.length; i++){
      totalAmount += this.cookiesPerHourArray[i];
    }
    return totalAmount;
  },
};
paris.custPerHour();
paris.cookiesPerHour();
paris.totalCookies();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var lima = {
  cityName: 'Lima',
  customerMax: 16,
  customerMin: 2,
  avg: 4.6,
  cookiesPerHourArray: [],
  custPerHourArray: [],
  render: function(){
    var salesData = document.getElementById('salesData');
    var timeLists = document.createElement('ul');
    timeLists.textContent =this.cityName;
    for(var i = 0; i < hoursArray.length; i++){
      var timeOfDay = document.createElement('li');
      timeOfDay.textContent = `${hoursArray[i]}${this.cookiesPerHourArray[i]}` ;
      timeLists.appendChild(timeOfDay);
    }
    salesData.appendChild(timeLists);
    var total = document.createElement('li');

    total.textContent = 'Total || ' + this.totalCookies();

    timeLists.appendChild(total);
  },
  custPerHour: function(){
    console.log('lima: customers');
    //This 'for' loop fills the custPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCust generates random numbers for the associated array
      var randomCust = Math.floor(Math.random()*(this.customerMax - this.customerMin ) + this.customerMin);
      //Pushes the values generated by randomCust into the array
      this.custPerHourArray.push(randomCust);
      //This displays the values in the browser console
      console.log(this.custPerHourArray);
    }
  },
  cookiesPerHour: function(){
    console.log('lima: cookies');
    //This 'for' loop fills the cookiesPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCookie generates random numbers for the associated array
      var randomCookie = Math.floor((Math.random()*(this.customerMax - this.customerMin) + this.customerMin) * this.avg);
      //Pushes the values generated by randomCookie into the array
      this.cookiesPerHourArray.push(randomCookie);
      //This displays the values in the browser console
      console.log(this.cookiesPerHourArray);
    }
  },
  totalCookies: function(){
    var totalAmount = 0;
    for(var i=0; i < this.cookiesPerHourArray.length; i++){
      totalAmount += this.cookiesPerHourArray[i];
    }
    return totalAmount;
  },
};
lima.custPerHour();
lima.cookiesPerHour();
lima.totalCookies();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
seattle.render();
tokyo.render();
dubai.render();
paris.render();
lima.render();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function City(cityName, customerMax, customerMin, avg){
  this.cityName = cityName;
  this.customerMax = customerMax;
  this.customerMin = customerMin;
  this.avg = avg;
  this.cookiesPerHourArray = [];
  this.custPerHourArray = [];
  this.custPerHour = function(){
    console.log('seattle: customers');
    //This 'for' loop fills the custPerHourArray with randomly generated values based on the given statistics.
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCust generates random numbers for the associated array
      var randomCust = Math.floor(Math.random()*(this.customerMax - this.customerMin ) + this.customerMin);
      //Pushes the values generated by randomCust into the array
      this.custPerHourArray.push(randomCust);
      //This displays the values in the browser console
      console.log(this.custPerHourArray);
    }
  };
  this.cookiesPerHour = function(){
    console.log('seattle: cookies');
    //This 'for' loop fills the cookiesPerHourArray with randomly generated values
    for(var i = 0; i < hoursArray.length; i++){
      //var randomCookie generates random numbers for the associated array
      var randomCookie = Math.floor(getRandomIntInclusive(this.customerMin, this.customerMax) * this.avg);
      //Pushes the values generated by randomCookie into the array
      this.cookiesPerHourArray.push(randomCookie);
      //This displays the values in the browser console
      console.log(this.cookiesPerHourArray);
    }
  };
  this.totalCookies = function(){
    var totalAmount = 0;
    for(var i=0; i < this.cookiesPerHourArray.length; i++){
      totalAmount += this.cookiesPerHourArray[i];
      // this.totalCookiesArray.push(totalAmount);
    }
    return totalAmount;
  };
}
City.prototype.render = function(){
  var salesData = document.getElementById('salesData');
  var timeLists = document.createElement('tr');
  timeLists.textContent ='Cookies || ';
  for(var i = 0; i < hoursArray.length; i++){
    var timeOfDay = document.createElement('th');
    timeOfDay.textContent = `${hoursArray[i]}`;
    timeLists.appendChild(timeOfDay);
  }
  salesData.appendChild(timeLists);
  //This block of code adds a list item that displays the total amount of cookies bought over the course of the day. It is populated by the "totalCookies" method.
  var total = document.createElement('th');
  total.textContent = 'Total ||';
  timeLists.appendChild(total);
};
var Austin = new City('Austin', 65, 23, 2.3);
console.log(Austin.cityName);
console.log(Austin.totalCookies());
Austin.custPerHour();
Austin.cookiesPerHour();
Austin.totalCookies();
Austin.render();
 
