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

119
Visualizações
Javascript Pin Code Validation add number 0

I'm still pretty new to the whole javascript environment. At the moment I'm trying to add the number 0 to a pin code pad. However, the number 0 is always granted as 10 can someone help me where the error lies?

Here is the link to the code

(function() {
    var input   = "",
        correct = "1593";
    
    var dots    = document.querySelectorAll(".dot"), 
        numbers = document.querySelectorAll(".number");
        dots    = Array.prototype.slice.call(dots);
        numbers = Array.prototype.slice.call(numbers);
    
    numbers.forEach(function(number, index) {
        number.addEventListener('click', function() {
            number.className += ' grow';
            input += (index+1);
            dots[input.length-1].className += ' active';
            if(input.length >= 4) {
                if(input !== correct) {
                    dots.forEach(function(dot, index) {
                        dot.className += " wrong";
                    });
                    document.body.className += " wrong";
                }
                else {
                    dots.forEach(function(dot, index) {
                        dot.className += " correct";
                    });
                    document.body.className += " correct";
                }
                setTimeout(function() {
                    dots.forEach(function(dot, index) {
                        dot.className = "dot";
                    });
                    input = "";
                }, 900);
                setTimeout(function() {
                    document.body.className = "";
                }, 2000);
            }
            setTimeout(function() {
                number.className = 'number';
            }, 1000);
        });
    });
})();

https://codepen.io/HBMBR/pen/bppXyE

Thanks for your help.

about 4 years ago · Juan Pablo Isaza
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