I’m building a shopping cart and i encountered a problem,
this cart takes in a product, if a product already exist, increment its amount
for decrementing if the item amount is ===1, add to cart
and i decrement, remove it from the array, otherwise just decrement the amount
now the incrementing works, Increment
my issue now is the decrementing
to understand the issue better i will create a use case, however you can skip and just look at the code snippets in my solution attempts
decrement
(Use case)
we wont touch on the incrementing, again, it works
for the decrement however, imagine we have a vase in our cart at $100,
name: 'vase',
price: 100,
description:'ceramic',
image: '../assets/vase.png',
BlackFridaySale: true,
amount: 0 //when we add an item the amount is set to 1
}]````
when we increment to 3 vases, the price updates to 300$, however when i decrement, instead of remove 100 dollars which is the price of one, it removes the whole $300 and sets the price to 0
I'd appreciate some insight
it seems i am somehow editing the same instance of my items in the array and i don't know where its coming from
i tried a for loop in the decrement logic, I'll also put the rest of the important snippets so i don't leave any gray area