diff --git a/Scripts/Checkout/orderSummary.js b/Scripts/Checkout/orderSummary.js
new file mode 100644
index 00000000..45cb1d1c
--- /dev/null
+++ b/Scripts/Checkout/orderSummary.js
@@ -0,0 +1,163 @@
+import {cart, removeFromCart, updateDeliveryOption} from '../../data/cart.js';
+import {products, getProduct} from '../../data/products.js';
+import { formatCurrency } from '../utils/money.js';
+import { deliveryOptions, getDeliveryOption } from '../../data/deliveryOptions.js';
+import dayjs from 'https://unpkg.com/dayjs@1.11.10/esm/index.js';
+import { renderPaymentSummary } from './paymentSummary.js';
+
+
+let cartSummaryHTML='';
+
+
+export function renderOrderSummary(){
+
+
+ cart.forEach((item)=>{
+
+ const productId=item.productId;
+
+ const matchingProduct=getProduct(productId);
+
+
+
+
+ const deliveryOptionId=item.deliveryOptionId;
+
+ const deliveryOption=getDeliveryOption(deliveryOptionId);
+
+ const today=dayjs();
+ const deliveryDate=today.add(
+ deliveryOptions.deliveryDays,
+ 'days'
+ );
+
+ const dateStringf=deliveryDate.format(
+ 'dddd,MMMM D'
+ );
+
+ cartSummaryHTML=cartSummaryHTML+`
+
+
+ Delivery date: ${dateStringf}
+
+
+
+
+
+
+
+ ${matchingProduct.name}
+
+
+ $${formatCurrency(matchingProduct.priceCents)}
+
+
+
+ Quantity: ${item.quantity}
+
+
+ Update
+
+
+ Delete
+
+
+
+
+
+
+ Choose a delivery option:
+
+
+ ${deliveryOptionsHTML(matchingProduct, item)}
+
+
+
+ `;
+ });
+
+ function deliveryOptionsHTML(matchingProduct, item){
+
+ let html='';
+
+ deliveryOptions.forEach((deliveryOption)=>{
+ const today=dayjs();
+ const deliveryDate=today.add(
+ deliveryOption.deliveryDays,
+ 'days'
+ );
+
+ const dateString=deliveryDate.format(
+ 'dddd,MMMM D'
+ );
+
+ const priceString=deliveryOption.priceCents
+ ===0
+ ? 'FREE '
+ : `$${formatCurrency(deliveryOption.priceCents)}-`;
+
+ const isChecked=deliveryOption.id===item.deliveryOptionId
+
+
+ html+= `
+
+
+
+ ${dateString}
+
+
+ ${priceString} Shipping
+
+
+
`
+
+ });
+
+ return html;
+
+ }
+
+
+ document.querySelector('.js-order-summary')
+ .innerHTML=cartSummaryHTML;
+
+
+
+ document.querySelectorAll('.js-delete-link')
+ .forEach((link)=>{
+ link.addEventListener('click',()=>{
+ const productId=link.dataset.productId;
+ removeFromCart(productId);
+
+
+ const container=document.querySelector(
+ `.js-cart-item-container-${productId}`);
+
+ container.remove();
+
+ renderPaymentSummary();
+
+ });
+
+ });
+
+ document.querySelectorAll('.js-delivery-option')
+ .forEach((element)=>{
+ element.addEventListener('click',()=>{
+ const {productId,deliveryOptionId}=element.dataset;
+ updateDeliveryOption(productId,deliveryOptionId);
+
+ renderPaymentSummary();
+ });
+ });
+
+}
+
+
diff --git a/Scripts/Checkout/paymentSummary.js b/Scripts/Checkout/paymentSummary.js
new file mode 100644
index 00000000..1b07ba18
--- /dev/null
+++ b/Scripts/Checkout/paymentSummary.js
@@ -0,0 +1,67 @@
+import {cart} from '../../data/cart.js'
+import { getProduct } from '../../data/products.js';
+import { getDeliveryOption } from '../../data/deliveryOptions.js';
+import {formatCurrency} from '../utils/money.js'
+
+
+export function renderPaymentSummary(){
+ let productPriceCents = 0;
+ let shippingPriceCents =0;
+
+ cart.forEach((item)=>{
+ const product= getProduct(item.productId);
+ productPriceCents+=product.priceCents * item.quantity;
+
+ const deliveryOption=getDeliveryOption(item.deliveryOptionId);
+ shippingPriceCents+=deliveryOption.priceCents;
+
+ });
+
+ const totalBeforeTax =productPriceCents+shippingPriceCents;
+ const taxCents =totalBeforeTax*0.1;
+ const totalCents=totalBeforeTax+taxCents;
+
+ const paymentSummaryHTML =`
+
+
+ Order Summary
+
+
+
+
Items (3):
+
+ $${formatCurrency(productPriceCents)}
+
+
+
+
+
Shipping & handling:
+
$${formatCurrency(shippingPriceCents)}
+
+
+
+
Total before tax:
+
+ $${formatCurrency(totalBeforeTax)}
+
+
+
+
+
Estimated tax (10%):
+
$${formatCurrency(taxCents)}
+
+
+
+
Order total:
+
$${formatCurrency(totalCents)}
+
+
+
+
+
+ `;
+ document.querySelector('.js-payment-summary')
+ .innerHTML=paymentSummaryHTML;
+}
\ No newline at end of file
diff --git a/Scripts/amazon.js b/Scripts/amazon.js
new file mode 100644
index 00000000..cd9c2b9f
--- /dev/null
+++ b/Scripts/amazon.js
@@ -0,0 +1,106 @@
+import {cart, addToCart} from '../data/cart.js';
+import {products} from '../data/products.js';
+import { formatCurrency } from './utils/money.js';
+
+
+
+
+
+let productsHTML='';
+
+products.forEach((product)=>{
+ productsHTML+=`
+
+
+
+
+
+
+ ${product.name}
+
+
+
+
+
+ ${product.rating.count}
+
+
+
+
+ $${formatCurrency(product.priceCents)}
+
+
+
+
+
+
+
+
+
+
+ Added
+
+
+
+
`
+
+});
+
+
+
+document.querySelector('.js-products-grid').
+innerHTML=productsHTML;
+
+
+
+function updateCartQuantity(){
+
+ let cartQuantity=0;
+
+
+ cart.forEach((item)=>{
+ cartQuantity+=item.quantity
+ })
+
+ document.querySelector('.cart-quantity').innerHTML=cartQuantity;
+
+}
+
+
+document.querySelectorAll('.js-add-cart')
+ .forEach((button)=>{
+ button.addEventListener('click',()=>{
+ const productId=button.dataset.
+ productId;
+ addToCart(productId);
+ updateCartQuantity();
+
+
+
+
+
+
+ console.log(cartQuantity)
+ console.log(cart);
+
+ });
+
+
+ });
+
diff --git a/Scripts/checkout.js b/Scripts/checkout.js
new file mode 100644
index 00000000..3e6485c0
--- /dev/null
+++ b/Scripts/checkout.js
@@ -0,0 +1,6 @@
+import { renderOrderSummary } from "./Checkout/orderSummary.js";
+import { renderPaymentSummary} from "./Checkout/paymentSummary.js";
+
+
+renderOrderSummary();
+renderPaymentSummary();
\ No newline at end of file
diff --git a/Scripts/utils/money.js b/Scripts/utils/money.js
new file mode 100644
index 00000000..26efed37
--- /dev/null
+++ b/Scripts/utils/money.js
@@ -0,0 +1,5 @@
+export function formatCurrency(priceCents){
+ return (Math.round(priceCents) /100).toFixed(2);
+}
+
+export default formatCurrency;
\ No newline at end of file
diff --git a/amazon.html b/amazon.html
index d9f431b6..492707ce 100644
--- a/amazon.html
+++ b/amazon.html
@@ -45,161 +45,18 @@
-
-
-
-
-
-
-
- Black and Gray Athletic Cotton Socks - 6 Pairs
-
-
-
-
-
- 87
-
-
-
-
- $10.90
-
-
-
-
-
-
-
-
-
-
- Added
-
-
-
-
-
-
-
-
-
-
-
- Intermediate Size Basketball
-
-
-
-
-
- 127
-
-
-
-
- $20.95
-
-
-
-
-
-
-
-
-
-
- Added
-
-
-
-
-
-
-
-
-
-
-
- Adults Plain Cotton T-Shirt - 2 Pack
-
-
-
-
-
- 56
-
-
-
-
- $7.99
-
-
-
-
-
-
-
-
-
-
- Added
-
-
-
-
+
+
+
+