Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda