-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9208496
commit 8db6558
Showing
7 changed files
with
2,585 additions
and
1,362 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Shopping Cart</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f9; | ||
color: #333; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
.container { | ||
max-width: 800px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
} | ||
.shopping-cart { | ||
background: white; | ||
padding: 20px; | ||
border-radius: 5px; | ||
box-shadow: 0 0 10px rgba(0,0,0,0.1); | ||
} | ||
.cart-item { | ||
border-bottom: 1px solid #eee; | ||
padding: 10px 0; | ||
} | ||
.cart-item:last-child { | ||
border-bottom: none; | ||
} | ||
.item-details { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
.item-price { | ||
color: #333; | ||
} | ||
.total { | ||
font-weight: bold; | ||
margin-top: 20px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="shopping-cart"> | ||
<h2>Your Shopping Cart</h2> | ||
<div id="cart-items"></div> | ||
<div class="total"> | ||
Total Items: <span id="total-items">0</span> | | ||
Total Price: $<span id="total-price">0.00</span> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const cartItemsContainer = document.getElementById('cart-items'); | ||
const totalItemsElement = document.getElementById('total-items'); | ||
const totalPriceElement = document.getElementById('total-price'); | ||
|
||
const cartItems = JSON.parse(localStorage.getItem('cartItems')) || []; | ||
|
||
let totalItems = 0; | ||
let totalPrice = 0; | ||
|
||
cartItems.forEach(item => { | ||
totalItems += item.quantity; | ||
totalPrice += item.price * item.quantity; | ||
|
||
const itemElement = document.createElement('div'); | ||
itemElement.classList.add('cart-item'); | ||
itemElement.innerHTML = ` | ||
<div class="item-details"> | ||
<span>${item.name} (x${item.quantity})</span> | ||
<span class="item-price">$${item.price.toFixed(2)}</span> | ||
</div> | ||
`; | ||
cartItemsContainer.appendChild(itemElement); | ||
}); | ||
|
||
totalItemsElement.textContent = totalItems; | ||
totalPriceElement.textContent = totalPrice.toFixed(2); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.