From 641cbf7a73fc41980d77c56bd9bcf5f206fc0036 Mon Sep 17 00:00:00 2001 From: Facundo Saucedo <43495919@terciariourquiza.edu.ar> Date: Mon, 25 May 2026 13:03:03 -0300 Subject: [PATCH] feat: implement product listing and shopping cart functionality --- ejercicio8/ejercicio8.js | 67 ++++++++++++++++++++++++++++++++++++++++ ejercicio8/index.html | 7 ++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/ejercicio8/ejercicio8.js b/ejercicio8/ejercicio8.js index 6ce9e92..73f1cce 100644 --- a/ejercicio8/ejercicio8.js +++ b/ejercicio8/ejercicio8.js @@ -1 +1,68 @@ // Agregar aquí el código javascript + +const products = [ + { name: "Teclado", price: 8500 }, + { name: "Mouse", price: 4200 }, + { name: "Monitor", price: 62000 }, + { name: "Auriculares", price: 11000 }, + { name: "Webcam", price: 15500 } +]; + +const productList = document.getElementById('productList'); +const checkout = document.getElementById('checkout'); + +products.forEach(product => { + const productDiv = document.createElement('div'); + productDiv.textContent = `${product.name} - $${product.price} `; + const buyButton = document.createElement('button'); + buyButton.textContent = 'Comprar'; + productDiv.appendChild(buyButton); + productList.appendChild(productDiv); +}); + +const cart = new Map(); + +const renderCart = () => { + checkout.innerHTML = ''; + + if (cart.size === 0) { + checkout.innerHTML = '
Carrito vacío
'; + return; + } + + let totalPrice = 0; + + cart.forEach((quantity, product) => { + const lineTotal = product.price * quantity; + totalPrice += lineTotal; + + const itemRow = document.createElement('div'); + itemRow.innerHTML = ` +