Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating table #3

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions Js/main.js
Original file line number Diff line number Diff line change
@@ -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 = '<th>Location</th>';


for (let hour = 6; hour <= 19; hour++) {
let time = hour > 12 ? hour - 12 + ' PM' : hour + ' AM';
headerRow.innerHTML += `<th>${time}</th>`;
}

headerRow.innerHTML += '<th>Daily Location Total</th>';
salesTable.appendChild(headerRow);
}

function renderFooterRow() {
let salesTable = document.getElementById('sales-table');
let footerRow = document.createElement('tr');
footerRow.innerHTML = '<td>Totals</td>';


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 += `<td>${total}</td>`;
}

let grandTotal = hourlyTotals.reduce((acc, val) => acc + val, 0);
footerRow.innerHTML += `<td>${grandTotal}</td>`;

salesTable.appendChild(footerRow);
}

renderFooterRow();






Binary file added images/lighthouse1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
<img src="./images/salmon.png">
<hr>
</section>
<div id="container">
<p id="seattle">
<h1>Seattle</h1>
<ul>
<li>Hours: 6 AM - 7PM</li>
<li>Phone: 123-456-7890</li>
<li>Location: 2901 3rd Ave #300, Seattle, WA 98121</li>
</ul>
</p>
<p id="Tokyo">
<h1>Tokyo</h1>
<ul>
<li>Hours: 6 AM-7 PM</li>
<li>Phone:222-222-2222</li>
<li>Location: 1 Chome-1-2 Oshiage, Sumida City, Tokyo 131-8634</li>
</ul>
</p>
</div>
<footer>&copy; 2023 Pat's Salmon Cookies</footer>
</body>
</html>
12 changes: 3 additions & 9 deletions sales.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@
<a href="index.html">Home</a>
<a href="sales.html">Sales Data</a>
</nav>
<ul id="seattle-sales">Seattle</ul>
<table id="sales-table"></table>

<script src="./Js/main.js"></script>
<script src="./Js/seattle.js"></script>

<ul id="tokyo-sales">Tokyo</ul>
<script src="./Js/tokyo.js"></script>

<ul id="dubai-sales">Dubai</ul>
<script src="./Js/dubai.js"></script>

<ul id="lima-sales">Lima</ul>
<script src="./Js/lima.js"></script>

<ul id="paris-sales">Paris</ul>
<script src="./Js/paris.js"></script>

</body>
Expand Down