Теперь лучше?
.onclick=addToCart;
}
function addToCart(){
let id=this.getAttribute('data-id');
if(cart[id]==undefined){
cart[id]=1;
}
else{
cart[id]++;
}
localStorage.setItem('cart', JSON.stringify(cart) );
console.log(cart);
showMiniCart();
}
function checkCart(){
if ( localStorage.getItem('cart') != null) {
cart = JSON.parse (localStorage.getItem('cart'));
}
}
function showMiniCart(){
let out ='';
for (let key in cart){
out += key + ' --- '+cart[key]+'<br>';
}
document.querySelector('.cart').innerHTML+=(out);
}
showMiniCart();
]