so recently i've been having a problem with localStorage in JS. Every time i would press the button instead of adding 1 to var wood;
the output would add 1 to the left side of the output each time i pressed the button, so if i pressed the button 3 times instead of wood = 3
it would equal 111
instead. please help.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p id="output"></p>
<button onclick="collectWood()">collect wood</button>
<script>
var wood = +localStorage.getItem("woodSave");
document.getElementById('output').innerHTML = parseInt(wood);
localStorage.setItem("woodSave", wood);
if(wood >= 1000){
replace = (wood / 1000).toFixed(2) + "k";
wood = replace;
document.getElementById('output').innerHTML = wood;
}
function collectWood() {
wood = wood + 1;
document.getElementById('output').innerHTML = wood;
}
</script>
</body>
</html>