Jump to content

Coding

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 2409:40d0:2010:a6b8:8000:: (talk) at 13:24, 2 May 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Coding may refer to: <!DOCTYPE html> <html lang="en"> <head>

 <meta charset="UTF-8">
 <title>My E-Commerce Store</title>
 <link rel="stylesheet" href="style.css">

</head> <body>

My Online Store

Cart

     <script src="script.js"></script>
    

    </body> </html> body {

     font-family: Arial, sans-serif;
     padding: 20px;
    

    }

    1. products {
     display: flex;
     gap: 20px;
    

    }

    .product {

     border: 1px solid #ccc;
     padding: 10px;
     width: 150px;
     text-align: center;
    

    } const products = [

     { id: 1, name: "Shirt", price: 500 },
     { id: 2, name: "Jeans", price: 1200 },
     { id: 3, name: "Shoes", price: 1500 }
    

    ];

    const productsDiv = document.getElementById("products"); const cartUl = document.getElementById("cart");

    const cart = [];

    products.forEach(product => {

     const div = document.createElement("div");
     div.className = "product";
     div.innerHTML = `
    

    ${product.name}

    ₹${product.price}

       <button onclick="addToCart(${product.id})">Add to Cart</button>
     `;
     productsDiv.appendChild(div);
    

    });

    function addToCart(id) {

     const product = products.find(p => p.id === id);
     cart.push(product);
     renderCart();
    

    }

    function renderCart() {

     cartUl.innerHTML = "";
     cart.forEach(item => {
       const li = document.createElement("li");
       li.textContent = `${item.name} - ₹${item.price}`;
       cartUl.appendChild(li);
     });
    

    }

    Computer science

    Other uses

    See also