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