'localstorage item value resetting
I have javascript code below
let beer_JSON = {"name": "beer", "price": 2.99, "quantity": 0};
let beer = document.getElementById("beer");
function alert(){
Swal.fire({
position: 'top-end',
icon: 'success',
title: 'added',
showConfirmButton: false,
timer: 1500
});
}
beer.addEventListener("click", function() {
alert();
beer_JSON.quantity++;
localStorage.setItem('beer', JSON.stringify(beer_JSON));
});
My quantity value resets to 0 after page refreshes. How can I fix that
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
