by jonnycomputer · 3y ago · 0 comments
function decreaseCounter() {
let count = parseInt(window.localStorage.getItem("count"));
count = count - 1;
window.localStorage.setItem("count", count);
}
all values stored in localStorage and sessionStorage are strings, so you have to convert to a number. You'd probably want a try/catch in there somewhere if count is not yet defined in the store, unless that possibility is dealt with elsewhere in your code. Also, the counter might need to check for boundary conditions (e.g. it can be negative here). But that is beyond the scope of your question.No comments yet.