Design comparison
Solution retrospective
Hello, I have problems with the cart any help please.
Community feedback
- @AhmadYousif89Posted over 1 year ago
Hi Anouer π
Your solution looks good π, I see that you have a problem with the cart logic, I will just point out to the issues that I see and possible fixes if I can but you will have to provide more info about your problem.
-
the add to car counter start initially with 1 that supposedly means that you don't want the user to enter a value less than that but I can clearly decrease the counter to 0 π€·ββοΈ so I would prevent that or just start with 0 as initial value.
-
after decreasing the counter to 0 I can still add item with qty = 0 to the cart you should prevent that by adding some if condition like
if (counter === 0 ) return // rest of your code
- adding an item doesn't increase the qty but rather pushes the item again to the array, again you should only add the item once with qty =1 if it's the first time or increment qty by 1 or the counter value if the item already exist in the cart so you need to check if the item exist or not with some code like
const exItem = state.cart.find(item => item.id === payload.id) if (exItem) { // increment the qty here } else { // just set the qty to equal 1 }
-
after adding multiple item to the cart I can only remove the first one (and this issue relates to the previous one so if you fix the previous issue I think this one will also be fixed)
-
I think the cart container has some fixed width and height and that is not ideal for the inner elements to fit properly inside so try adding min-width and min-height instead (if you actually need to)
and that's some of what I have noticed so far but overall nice work. if you have any questions don't hesitate to ask π
Keep Coding π
Marked as helpful1 -
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