Design comparison
Solution retrospective
i am most proud of my javascript, it was difficult while writing the reload cart function but i was able to get it right.
What challenges did you encounter, and how did you overcome them?i was unable to write certain funtion, including the hover effect in the nav bar
Community feedback
- @jakegodsallPosted 5 months ago
Hi, great work with this project.
Just a few pointers:
-
I'd recommend representing the product as an array of objects rather than nested objects. This is because a typical API will use this pattern.
Rather than this
const products = { 1: { name: "Fall Limited Edition Sneakers", price: 125.0, image: "images/image-product-1.jpg", }, };
Like this
const products = [ { id: 1, name: "Fall Limited Edition Sneakers", price: 125.0, image: "images/image-product-1.jpg", }];
You'll have an easier time searching and filtering this way in the future.
-
When you click the "Add to cart" button, only 1 product is added to the cart regardless of how many are selected using the above selector. I've gone into your source code and got to the bottom of it. You're incrementing the quantity by 1 in the
addToCart
method. To fix this try:function addToCart(key) { if (listCards[key] == null) { listCards[key] = { ...products[key], quantity: +quantityElement.textContent, }; } else { listCards[key].quantity += +quantityElement.textContent; } }
Hope this helps. Keep up the good work ☺️
Marked as helpful0@Godbrand0Posted 5 months agohello, thanks for the feedback. your solutions to the bugs was really straight forward, the number increment was a hard nut to crack for me. thanks for your help on my web dev journey. @jakegodsall
0 -
Please log in to post a comment
Log in with GitHubJoin 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