Hello I'm creating a clicker game with HTML and Jquery
So im currently facing an issue with localstorage.getItem . I want to get the saved amount of cash after reloading the page.
Lets say i got 5 munny, i reload the page it will show the 5 munny i had. But when i click Munny to get more it restarts from 1
(booster variable is used for future upgrades, if anything)
<div class="floppa">
<h1 class="floppa">Munny</h1>
<h1 class="text">You got <span class="cash">0</span> munny</h1>
</div>
var cash;
var booster = 1;
cash = 0;
$('h1.floppa').on('click', function(){
$('span.cash').text(cash += booster)
localStorage.setItem('cash', cash)
})
//---get saved item from localstorage---//
cash = localStorage.getItem('cash')
$('span.cash').text(cash)