Ask coding questions

← Back to all posts
Button not functioning
AstrumDeorum (10)

So, I'm working on implementing Upgrades, however, the upgrade I'm working on (which happens to be the first) isn't working, because the button to get it isn't functioning.
I don't see an immediate issue, since it's virtually identical to all my building purchase buttons in how it works.
The commented part in the criteria is so I can figure out how to make it work before adding in a whole bunch of stuff to check.

function buyClickUp1() {
      if (cookies >= cur1Value /*&& clickers > 0 && curUp1 == false*/){
        cookies -= cur1Value;
        clickerCPS *= 2;
        cpc *= 2;
        curUp1 = true;
        document.getElementById("cookieCount").innerHTML = Math.floor(cookies);
<th><button onclick="buyClickUp1()"><img src="CurUp/CursorUp1.png"><br><img src="smolkie.png">100</button></th>
Coder100 (16760)

I really recommend you instead of manually doing these things, you should abstract everything away with a good old for loop and an array.

Not only will less bugs like this be made, you can also create more items easier and faster!

AstrumDeorum (10)

@Coder100 Mind to drop an example, I'm rather novice at this.
I haven't learned how to do stuff like that yet, and I guess that kind of shows, my stuff's a mess.

Coder100 (16760)
let items = [{
  name: "...",
  price: 59

for (const itm of arrs) {
  // insert element using `itm`


AstrumDeorum (10)

@Coder100 I... Still don't understand that. Sorry, I haven't worked with any of this yet, and I'm a little slow to pick up some concepts.
If you'd be able to put a second item in the array and a line in the loop that actually shows what you mean, I should be good. I just want clarification on what you mean.

Coder100 (16760)


let arr = [{ ... }, { ... }];
for (const itm of arr) {
  const el = document.createElement("div");
  // set the innerhtml
  el.innerHTML = "...";



AstrumDeorum (10)

I guess I just shouldn't add so many variables.
It works now.