wizviper wizviper -4 years ago 100
HTML Question

Image shows if condition is met

I am making a cookie clicker-esque game and i am making an upgrade bar. One icon starts off invisible and once you have 1 cursor it becomes visible. The problem is it isn't.

I have looked thoroughly and still can't find the bug.
This is in JSFiddle.
Here it is-https://jsfiddle.net/wizviper/mq0qwnvr/
Main Code-

document.getElementById("reinforcedFingerShop").addEventListener(cursorAmount >= 1, function() {

if (reinforcedFingerActive = 0) {




Answer Source

addEventListener listens to events but you are assigning a condition to it "cursorAmount >= 1". I guess you probably want to know when (cursorAmount >= 1) and also (reinforcedFingerActive == 0), please provide the related part of your code, so that we will be able to help you better


You are changing cursorAmount inside "cursorShop" function so the best place to check "reinforcedFingerActive == 0" condition is there.

document.getElementById("cursorShop").onclick = function() {
    if (cookies >= cursorPrice) {
      cookies = cookies - cursorPrice;
      cursorPrice = cursorPrice * 1.15;
      cps = cps + 0.1;
      cursorAmount = cursorAmount + 1;
      if (reinforcedFingerActive == 0) {

I have not tested but it should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download