Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Product list with cart solution

P

@amjadsh97

Desktop design screenshot for the Product list with cart coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


What are you most proud of, and what would you do differently next time?

I learned how to handle product counts, unique product lists, and total price calculations in a shopping cart context using JavaScript. Here's a breakdown of what I implemented:

  // Calculate the count of each product
const productCounts = selectedProducts.reduce((acc, product) => {
	acc[product.name] = (acc[product.name] || 0) + 1;
	return acc;
}, {} as Record);

// Create a list of unique products with their counts
const uniqueProducts = selectedProducts.reduce((acc: Product[], product) => {
	if (!acc.find(p => p.name === product.name)) {
		acc.push(product);
	}
	return acc;
}, []);

// Calculate total price
const totalPrice = selectedProducts.reduce((acc, product) => acc + product.price, 0);



### What specific areas of your project would you like help with?
I want feedback on state management

Community feedback

grgrnkoo 520

@grgrnkoo

Posted

Good job! All nuances are perfectly worked out! Can not find anything that could be upgraded!

Marked as helpful

0

P

@amjadsh97

Posted

Thank you@grgrnkoo

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord