Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Sorry, you do not have permission to ask a question, You must login to ask a question. Please subscribe to paid membership

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Home Special

 

 

Welcome to My Online Store

Product Image

Product 1

Price: $10



Product Image

Product 2

Price: $20



Product Image

Product 3

Price: $30



Product Image

Product 4

Price: $40



Product Image

Product 5

Price: $50



Product Image

Product 6

Price: $60



Product 7

Product 7

$20.99



function addToCart(item) {
// Get the item details
var itemName = item.getAttribute(“data-name”);
var itemPrice = parseFloat(item.getAttribute(“data-price”));

// Create a new cart item object
var cartItem = {
name: itemName,
price: itemPrice,
quantity: 1
};

// Check if the item already exists in the cart
for (var i = 0; i < cart.length; i++) { if (cart[i].name === itemName) { cart[i].quantity++; saveCart(); return; } } // If the item is not already in the cart, add it cart.push(cartItem); saveCart(); } // Update the total price function updateTotal() { var total = 0; for (var i = 0; i < cart.length; i++) { total += cart[i].price * cart[i].quantity; } document.getElementById("total-price").innerHTML = total.toFixed(2); } function addToCart(item) { // Get the item details var itemName = item.getAttribute("data-name"); var itemPrice = parseFloat(item.getAttribute("data-price")); // Create a new cart item object var cartItem = { name: itemName, price: itemPrice, quantity: 1 }; // Check if the item already exists in the cart for (var i = 0; i < cart.length; i++) { if (cart[i].name === itemName) { cart[i].quantity++; saveCart(); return; } } // If the item is not already in the cart, add it cart.push(cartItem); saveCart(); updateTotal(); } // Update the total price function updateTotal() { var total = 0; for (var i = 0; i < cart.length; i++) { total += cart[i].price * cart[i].quantity; } document.getElementById("total-price").innerHTML = total.toFixed(2); } // Save the cart to localStorage function saveCart() { localStorage.setItem("cart", JSON.stringify(cart)); }