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

173
Vistas
Is there a way to make an iterator variable greater than something and less then something?

So, the assignment is generating a random password between 7-10 characters. Is this valid syntax in my for loop which generates the amount of numbers.

var password = "";
var characters =
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789@#$";
for (i = 1; i <= 10; i++) {
  var char = Math.floor(Math.random() * characters.length + 1);
  password += characters.charAt(char);
}
console.log(password);

So, this current for loop makes the password ten characters. I want it to be between 7 and 10 characters. Is it valid Javascript syntax to do i<=10 && i>=7?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

What you can do is select a random number from 0 to 3. Based on that number, you will decide how long your password is. Could be 7+0 or 7+1 or 7+2 or 7+3.

Now the number of times your loop runs is dynamic and hence you will get passwords of different lengths.

var password = "";
var characters =
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789@#$";

let x = Math.floor(Math.random()*4);
for (i = 1; i <= (7+x); i++) {
  var char = Math.floor(Math.random() * characters.length + 1);
  password += characters.charAt(char);
}
console.log(password);

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