DerekBogie Posted April 26, 2015 Share Posted April 26, 2015 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 More sharing options...
Ingolme Posted April 26, 2015 Share Posted April 26, 2015 You can cast to number before operating: localStorage.gold = Number(localStorage.gold) + tempCount; Link to comment Share on other sites More sharing options...
DerekBogie Posted April 26, 2015 Author Share Posted April 26, 2015 (edited) Wow I didn't even realize i was missing "Number" Yet again lngolme you come to my rescue. Edited April 26, 2015 by DerekBogie Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now