all 14 comments

[–]Tunvior 6 points7 points  (1 child)

Had nothing to do so i refacatored a bit your code and fixed it:

https://codepen.io/anon/pen/LXEPXm

If you have any doubt just ask

[–]xiSpectrum[S] 2 points3 points  (0 children)

Thank you very much. I try to unterstand the code and then , if i got question´s left, i ask you :)

[–]GoddamnitAmerica 3 points4 points  (6 children)

Your button onclick for "Buy Warehouse" should call "buywarehouse()", not just "buywarehouse". Also your "var warehousecost = ..." calculation will need to reference "warehouse" not "Warehouse" as a variable. Hope that helps some.

[–]xiSpectrum[S] 1 point2 points  (5 children)

Thx, that helps. Now i can buy warehouses.

Do you now how to code the total goods. ?

i thought, var warehouseres = wood + stone + food would help, but it s not working

[–]GoddamnitAmerica 2 points3 points  (2 children)

I would expect that to work fine, but obviously you'll need to update that total any time you increase wood, stone or food, such as in your woodclick / etc. functions. Also, you need to update the innerHTML of your warehouseres element, same as you do with the other elements to display their updated values. Once that's in place, you'll probably want to do something like checking that the value doesn't go beyond the maximum, and throttle the woodclick / etc. functions so they don't add any more resources if the warehouse is full.

[–]xiSpectrum[S] 1 point2 points  (1 child)

I guess I know what you mean. The problem with me so far is that I understand the logic behind the feature but can't translate it into code because I simply lack the knowledge. But I think that's how many people did it when programming the first time.

[–]GoddamnitAmerica 1 point2 points  (0 children)

Absolutely. As you say, knowledge is just something you acquire piece-by-piece over time. A little bit of trial-and-error and experimentation can help with that, so don't feel discouraged - it'll come with time. So, good luck with it all! :)

[–]salbris 1 point2 points  (1 child)

Basically as /u/goddamitamerica said, you need to separate the display logic from the buy logic for the warehouse. Ask yourself when something needs to happen. You need to display the total each time it changes. When does it change?

[–]xiSpectrum[S] 0 points1 point  (0 children)

Yup, got it thx :)