Ask coding questions

← Back to all posts
How can I do a real working buying function?
ichbindede

How can I do a real working buying function? I will do an inventory system that really works. So like when apple is 10 clicks and you have 9 clicks you can't buy. If you have 10 golds or more you can buy. I worked on it a bit but I can't do that.

Voters
ichbindede
Comments
hotnewtop
MrVoo

It's as simple as this:

Didn't I already answer this?

ichbindede

yes you did. but i want to make buying things with the counter label @MrVoo

ichbindede

i tried to make with the counter label but it didnt work. i tried with counterVal but it didn't work aswell. @MrVoo

MrVoo

@ichbindede What do you mean, a "counter label"?

ichbindede

the click counter @MrVoo

MrVoo

@ichbindede Put your counter upgrade function inside the buy function.

ichbindede

I made this code but there's a bug that i can not explain you can test by opening console and see.

how can I fix? @MrVoo

MrVoo

@ichbindede You coded it so you have to do updateDisplay() when you want to do that, so add it in the function.

ichbindede

where to add it. when i add it, when i buy apples it says undefined. @MrVoo

MrVoo

@ichbindede What says undefined?

ichbindede

test it
@MrVoo

MrVoo

@ichbindede Your funky code requires that you do updateDisplay(counterVal) instead of just updateDisplay() :/

ichbindede

thanks now its working but still when it buys it still prints Not enough money in the console @MrVoo

MrVoo

@ichbindede Don't add the equals sign in that condition

ichbindede

ok i did it but it still happening @MrVoo

MrVoo

@ichbindede It's better if you don't put it in a console.log() thing, but if you really want to, put it before the if statement that buys the apples