0

I looked on whole stack overflow but unfortunately, answer of this question wasn't available so I have a class and inside I have a function donutMaker and inside of this function I want to call another function which is autoClicker but it is not being called:

class DonutMaker {
  constructor() {
    this.donut_creater = document.getElementById("donut_creater");
    this.donut_creater.addEventListener("click", this.donutMaker);

    this.auto_clicker = document.getElementById("auto_clicker");
    this.auto_clicker.addEventListener("click", this.autoClickerHandler);
  }

  donutMaker() {
    this.selection = document.getElementById("donut_quantity");
    this.quantity = this.selection.innerText;
    this.updated_quantity = parseInt(this.quantity);
    this.updated_quantity = this.updated_quantity + 1;
    this.selection.innerText = this.updated_quantity;
  }
  autoClickerHandler = () => {
    this.selection = document.getElementById("donut_quantity");
    this.quantity = this.selection.innerText;
    this.updated_quantity = parseInt(this.quantity);
    this.new_quantity = this.updated_quantity - 1;

    if (this.updated_quantity >= 1) {
      this.selection.innerText = this.new_quantity;
      this.quantity = this.new_quantity;
      this.selection2 = document.getElementById("auto_clicker_quantity");
      this.auto_clicker_quantity = this.selection2.innerText;
      this.auto_clicker_quantity = parseInt(this.auto_clicker_quantity);
      this.auto_clicker_quantity_updated = this.auto_clicker_quantity + 1;
      this.selection2.innerText = this.auto_clicker_quantity_updated;
      this.autoClicker;
    } else {
      console.log("Not Eligible");
    }
  };
  autoClicker = () => {
    console.log("Hello");
    // console.log("Auto clicker");
  };
}

let obj = new DonutMaker();

This line at the end of if supposed to call this.autoClicker but it isnt

Ayan Khan
  • 53
  • 6

2 Answers2

1

You forgot to call it

this.autoClicker();
soffyo
  • 545
  • 5
  • 15
1

Take a look at the ‘Calling Functions’ section of the mdn docs.

Defining a function does not execute it but calling it this.autoClicker() does.