I have a store were I want it to be possible to click on a product until the stock is out. The stock is 10. How can I make so only the clicked button disables when reached 10 clicks, and the other ones continue working? Stock is Lager = 10. Products is the array. The buttons are hardcoded in html.
let products = [
{
id: 0,
namn: 'Sneaker1',
img: 0,
pris: 1500,
lager: 10,
inCart: 0
},
{
id: 1,
namn: 'Sneaker2',
img: 1,
pris: 1500,
lager: 10,
inCart: 0
},
{
id: 2,
namn: 'Sneaker3',
img: 2,
pris: 1500,
lager: 10,
inCart: 0
},
{
id: 3,
namn: 'Sneaker4',
img: 3,
pris: 1500,
lager: 10,
inCart: 0
},
{
id: 4,
namn: 'Sneaker5',
img: 4,
pris: 1500,
lager: 10,
inCart: 0
}
]
const euro = document.querySelectorAll('.euro')
for(let i = 0; i < euro.length; i++ ){
euro[i].addEventListener('click', () => {
cartNumbers(products[i])
totalCost(products[i])
products.map((product) => {
if(product.inCart >= 10){
for(var i = 0; i < euro.length; i++) {
euro[i].disabled = true;
}
}
})
})
}