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

91
Views
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 answers
Answer question

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