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

120
Vistas
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 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