Jump to content

LocalStorage Problem


DerekBogie

Recommended Posts

I am coding a game and have came into a snag. I am using localStorage to keep track of players gold. I coded a button to sell "eggs" for $150 per egg. When i try to add the value from the sale to localStorage.gold it adds it on the ending of it. So lets say the gold is 100.... if you sell 1 egg and get $150 it will make the gold count 100150. I know there is a method that i am not doing to properly do this in JSON but i cannot figure it out. any help would be appreciated.

function conciergeSell() {     if (tempCount <= localStorage.eggs && localStorage.eggs !== 0 && tempCount > 0) {         soundReset.play();         localStorage.eggs = localStorage.eggs - tempCount;         tempCount = tempCount * 150;         localStorage.gold = localStorage.gold + tempCount;          tempCount = 0;         document.getElementById("conciergeTotal").innerHTML = tempCount;         document.getElementById("playerEggs").innerHTML = localStorage.eggs;         document.getElementById("playerGold").innerHTML = localStorage.gold;       }}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...