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

130
Views
Generar contraseña a través de Javascript y renderizar de nuevo a HTML

Entonces, estoy tratando de construir un generador de contraseñas simple a través de JavaScript y la función simplemente no devolverá nada, no devolverá nada (en blanco).

 let chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ" let randomPass = "" let passLen = 16 function ranNum() { for ( let i=0; i<passLen.length; i++){ let randomLetter = Math.floor(Math.random() * chars.length) + 1 randomPass += chars.charAt(randomLetter) } return randomPass } function genPass() { document.getElementById("div1").textContent = ranNum() }
 <button onclick="genPass()">Generate</button> <div id="div1"></div>

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Su ciclo for no se está ejecutando porque está solicitando passLen.length, y passLen es un número entero, no tendrá una longitud, y luego el ciclo no se ejecutará. simplemente cambie su línea for ( let i=0; i<passLen.length; i++){ a for ( let i=0; i<passLen; i++){ y funcionará bien.

 let chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ" let randomPass = "" let passLen = 16 function ranNum() { console.log('generate'); for ( let i=0; i<passLen; i++){ let randomLetter = Math.floor(Math.random() * chars.length) + 1 randomPass += chars.charAt(randomLetter); console.log(randomLetter); } return randomPass } function genPass() { document.getElementById("div1").textContent = ranNum() }
 <div id="div1">test</div> <button onclick="genPass()">Generate password</button>

about 4 years ago · Juan Pablo Isaza Report

0

Es porque tienes la propiedad de longitud en passLen y el valor de la variable es un int.

 for ( let i=0; i<passLen; i++){ let randomLetter = Math.floor(Math.random() * chars.length) + 1 randomPass += chars.charAt(randomLetter) }
about 4 years ago · Juan Pablo Isaza Report

0

En su bucle for, passLen no es una matriz, ya es una longitud. Entonces no necesita passLen.length solo passLen .

 let chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ" let randomPass = "" let passLen = 16 function ranNum() { for (let i = 0; i < passLen; i++) { let randomLetter = Math.floor(Math.random() * chars.length) + 1 randomPass += chars.charAt(randomLetter) console.log(randomPass) } return randomPass } function genPass() { document.getElementById("div1").textContent = ranNum() }
 <button onclick="genPass()">Generate</button> <div id="div1"></div>

about 4 years ago · Juan Pablo Isaza Report
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!