Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
¿Por qué no puedo recuperar números de la segunda y tercera entrada?

No puedo recuperar números de dos entradas. La primera entrada #inpArraysNumber funciona bien. El segundo y el tercero no. No sé qué estoy haciendo mal. ¿Podría por favor decirme cómo resolver este problema?

 // 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>

Cuando configuro las variables min y max en mi código, todo funciona bien.

establecer estas dos variables funciona bien:

sea min = 55;

sea max = 155;

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!