Javascript check random vector

0

Greetings, I created a function in Js that when the user enters the numbers works perfectly , but when that function is called but instead of entering the numbers, randomly generated does not work, it comes out an "undefined":

 function comenzar(){

         var numeritos = document.formu.elements["num[]"];
         var correcto = Comprobaciones(numeritos);

         if(correcto){
             maquina_boleto();
         }

    }

function Comprobaciones(numeritos){

          var correcto=true;

          for ( var i = 0 ; i < numeritos.length; i ++){
               if(numeritos[i].value < 1 || numeritos[i].value > 49){  
                            numeritos[i].value="";
                            correcto=false;
                }
             for(var j = i +1 ; j < numeritos.length;j++){
                 if(numeritos[i].value == numeritos[j].value){
                      numeritos[j].value="";
                      correcto=false;
                      alert("se repite el" + numeritos[i].value + " j vale" +  numeritos[j].value );
                 }
             }
         }

         return correcto;
      }

So far everything is fine, check and correct the repeated. but when I do it it becomes random:

 function maquina_boleto(){

            var maq=[];
            var correcto=true;

            for(var i = 0 ; i < 6 ; i++){
                    maq[i] =  Math.floor((Math.random()*20)) +1;
            }

        alert("vector maq >");
        alert(maq);


        for(var i = 0 ; i < maq.length;i++){
            do{
                correcto =  Comprobaciones(maq);
                if(!correcto) {
                    maq[i]= Math.floor((Math.random()*20)) +1;
                }
            }while(!correcto);

         alert("vector maq 2 >");
         alert(maq);
         }
    }

When I fill in the random vector and call the check function, it enters the if because the numbers [i] .value VALE UNDEFINED and the numbers [j] .value VALE UNDEFINED and stays in an infinite loop.

Can you help me? Thanks

    
asked by EduBw 23.09.2017 в 02:36
source

1 answer

0

The problem is the Array numeritos when you randomly load it is an array of integers. Integers do not have the value property, so numeritos[i].value returns undefined .

In contrast, when you load from the form, the variable numerito is a HTML Collection whose if elements have the property value

    
answered by 25.09.2017 / 17:12
source