Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda