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

246
Vistas
Why can't I retrieve numbers from second and third input?

I can't retrieve numbers from two inputs. First input #inpArraysNumber works fine. Second and third doesn't. I don't know what I am doing wrong. Could you please tell me how to solve this problem?

// this doesn't work
let min = document.getElementById("inpMinValue").value;
let max = document.getElementById("inpMaxValue").value;

// this works
let N = document.getElementById("inpArraysNumber").value;

JS

const btnClick = document.getElementById("btnClick");
var buttonFlag = false;
btnClick.addEventListener("click", onClick);

function onClick(){
    
    // one click
    if (buttonFlag){
        console.log(buttonFlag);
        return;
    }
    buttonFlag = true;
     
    const nums = [];
    let N = document.getElementById("inpArraysNumber").value;
    
    for(let i=0; i<N; i++){
        nums[i] = [];
    }
    const uniqueNumber = function (minValue, maxValue, maxSubarrayIndex) {
        const number = Math.floor(Math.random() * (maxValue - minValue + 1) + minValue);
        const subarrays = nums.slice(0, maxSubarrayIndex + 1);
        if (subarrays.every(subarr => !subarr.includes(number))) {
            nums[maxSubarrayIndex].push(number);
        } else {
            uniqueNumber(minValue, maxValue, maxSubarrayIndex);
        }
    }
    // this doesn't work
    let min = document.getElementById("inpMinValue").value;
    let max = document.getElementById("inpMaxValue").value;

    // this works fine
    // let min = 55;
    // let max = 155;

    const howMany = parseInt((max-min)/N);
    for(let i=0; i<N; i++){
        for(let j=0; j<howMany; j++){
            uniqueNumber(min, max, i);
        }
    }
 // here more code, but I couldn't post it because of "your post is mostly code"
}

HTML


<body>
    <div id="numbers">
        <h1>Unique numbers in Arrays</h1>
        <div id="inputsDiv">
            <input type="number" id="inpArraysNumber" placeholder="Arrays number">
            <input type="number" id="inpMinValue" placeholder="Min value">
            <input type="number" id="inpMaxValue" placeholder="Max value">
            <button id="btnClick">click</button>
        </div>
        <div id="innerNumbers">
        </div>
    </div>
    <script src="./js/script.js"></script>
</body>

When I set min and max variables in my code everything works fine.

setting theese two variables works fine:

let min = 55;

let max = 155;

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