Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Function not firing when AC button pressed

I have a masterFunction which should fire another function called reset when the AC button on my calculator is pressed (picked up via e.target.id = "AC").

However it's not firing, in fact no functions are firing when I press the AC button.

I've added a console log and can see e.target.id = "AC" yet it still won't fire.

Reduced code:

//Update display with button clicked
buttonGrid.addEventListener('click', e => {
console.log(e.target.id);
    masterFunction(e);
});

//Fire relevant function depending on the button pressed etc
let masterFunction = (e) => {
    if (e.target.id === "AC")  {
        reset(e);
    } 
}; 

// Reset the screen
  let reset = (e) => {
    secondNumberCounter = false;
    operatorPressed = false;
    firstNumber = 0;
    secondNumber = 0;
    buttonNumber = 0;
    decimalCounter = 0;
    displayArea.textContent = 0;
  };

Can anyone see what I'm doing wrong?

https://jsfiddle.net/2s9nuLj0/5/

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Because your first if condition is eating up the clicks. Basic debugging will show your problem.

    console.log('BEFORE THE IFS');
    if (operatorPressed === false && firstNumberCounter === true && e.target.dataset.type != "nonNumberFunction") { 
        console.log('I AM HERE!!!!')
        firstNumberPicker(e);
    }

and you should stop the default action of the clicks

buttonGrid.addEventListener('click', e => {
    masterFunction(e);
    e.preventDefault();
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!