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

93
Visualizações
Js newbie here. I wan't my passwords to include at least: 1 capital, 1 special character

I wanted my passwords to include at least: 1 capital, 1 special character I am trying with this while loop to meet the requirements. What am i doing wrong?

const characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#$!-_";
const capital = /ABCDEFGHIJKLMNOPQRSTUVWXYZ/;
const special = /#$!-_/; 

function PWord (){
      let pass = ""
      while(!((capital.test(pass)) && (special.test(pass))) ){
        for (i=0; i<=11; i++)
        {
          let rand_char = characters.charAt(Math.floor(Math.random()*characters.length));
          pass = pass + rand_char;
        }
        
        return pass
      }
}

for(let i=0;i<=3;i++){
  let ps = PWord();
  console.log("Password" + (i+1) + ":" + ps);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The main issue I see here is your use of return in the while loop. return will always end the execution of the entire function and return the specified value. The condition in your loop will only be checked once since you're returning before giving it the chance to check and run again. Try moving that line outside of the loop.

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