Untitled
const button = document.querySelectorAll('.add'); const btn = document.querySelectorAll('.remove'); const counter = document.getElementById('counter'); let count = 0; button.forEach(button => { button.addEventListener('click',function(){ count += 1; counter.textContent = count; alert('Item added to cart'); }); }); btn.forEach(btn =>{ btn.addEventListener('click', function(){ if(count>0){ count -=1; counter.textContent = count; }else{ alert('your cart is empty'); } alert('Item is remove from cart'); }); });
Leave a Comment