diff --git a/Js/main.js b/Js/main.js new file mode 100644 index 0000000..10131da --- /dev/null +++ b/Js/main.js @@ -0,0 +1,108 @@ + +function CookieStand(location, minCustomers, maxCustomers, avgCookiesPerSale) { + this.location = location; + this.minCustomers = minCustomers; + this.maxCustomers = maxCustomers; + this.avgCookiesPerSale = avgCookiesPerSale; + this.hourlySales = []; +} + + +CookieStand.prototype.generateHourlySales = function() { + for (let hour = 6; hour <= 19; hour++) { + let customers = Math.floor(Math.random() * (this.maxCustomers - this.minCustomers + 1)) + this.minCustomers; + let cookiesSold = Math.round(customers * this.avgCookiesPerSale); + this.hourlySales.push(cookiesSold); + } +}; + + +CookieStand.prototype.render = function() { + let salesTable = document.getElementById('sales-table'); + let row = document.createElement('tr'); + + + let locationCell = document.createElement('td'); + locationCell.textContent = this.location; + row.appendChild(locationCell); + + let dailyTotal = 0; + + for (let cookies of this.hourlySales) { + let cell = document.createElement('td'); + cell.textContent = cookies; + row.appendChild(cell); + dailyTotal += cookies; + } + let totalCell = document.createElement('td'); + totalCell.textContent = dailyTotal; + row.appendChild(totalCell); + + salesTable.appendChild(row); +}; + +renderHeaderRow(); + + +let seattle = new CookieStand('Seattle', 23, 65, 6.3); +let tokyo = new CookieStand('Tokyo', 3, 24, 1.2); +let dubai = new CookieStand('Dubai', 11, 38, 3.7); +let paris = new CookieStand('Paris', 20, 38, 2.3); +let lima = new CookieStand('Lima', 2, 16, 4.6); + + +let cookieStands = [seattle, tokyo, dubai, paris, lima]; +for (let stand of cookieStands) { + stand.generateHourlySales(); + stand.render(); +} + + +function renderHeaderRow() { + let salesTable = document.getElementById('sales-table'); + let headerRow = document.createElement('tr'); + headerRow.innerHTML = 'Location'; + + + for (let hour = 6; hour <= 19; hour++) { + let time = hour > 12 ? hour - 12 + ' PM' : hour + ' AM'; + headerRow.innerHTML += `${time}`; + } + + headerRow.innerHTML += 'Daily Location Total'; + salesTable.appendChild(headerRow); +} + +function renderFooterRow() { + let salesTable = document.getElementById('sales-table'); + let footerRow = document.createElement('tr'); + footerRow.innerHTML = 'Totals'; + + + let hourlyTotals = new Array(14).fill(0); + + + for (let stand of cookieStands) { + for (let i = 0; i < stand.hourlySales.length; i++) { + hourlyTotals[i] += stand.hourlySales[i]; + } + } + + + for (let total of hourlyTotals) { + footerRow.innerHTML += `${total}`; + } + + let grandTotal = hourlyTotals.reduce((acc, val) => acc + val, 0); + footerRow.innerHTML += `${grandTotal}`; + + salesTable.appendChild(footerRow); +} + +renderFooterRow(); + + + + + + diff --git a/images/lighthouse1.png b/images/lighthouse1.png new file mode 100644 index 0000000..f88ed8e Binary files /dev/null and b/images/lighthouse1.png differ diff --git a/index.html b/index.html index e9f8ec8..e68e597 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,24 @@
+
+

+

Seattle

+ +

+

+

Tokyo

+ +

+
diff --git a/sales.html b/sales.html index c0fcbd5..00dafa9 100644 --- a/sales.html +++ b/sales.html @@ -12,19 +12,13 @@ Home Sales Data - +
+ + - - - - - - - -