Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda