Coding
Topics referred to by the same term From Wikipedia, the free encyclopedia
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">
Look up coding in Wiktionary, the free dictionary.
</head> <body>
Cart
<script src="script.js"></script>
</body> </html> body {
font-family: Arial, sans-serif; padding: 20px;
}
- 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); });
}
Wikiwand - on
Seamless Wikipedia browsing. On steroids.