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

202
Views
Is there a way to reference all my strings in an array in a for() loop to make sure user meets criteria for selecting an uppercase letter

I am trying to create prompts for a user to choose if he would like his/her password to contain special characters, uppercase numbers, and lowercase numbers etc.. I created arrays for them, I figured that is the most convenient way; however, I need help in referencing the arrays to create the correct logic. (I got stuck on where you see the for loop)

// Assignment code here
document.querySelector('#generate').addEventListener("click", writePassword);

//Defined Array to full fill all the criteria options
var upper = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
var lower = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
var special = ["`", "~", "!", "@","#","$","%","^","&","*","(",")","-","_","=","+","{","}","|", "[","]","<",">","?","/","'",];
var number = ["1","2","3","4","5","6","7","8","9","0"];

//Variables assigned
var passwordLength;
var upperConfirm;
var lowerConfirm;
var specialConfrim;
var numberConfirm;

// Get references to the #generate element
var generateBtn = document.querySelector("#generate");

// Write password to the #password input
function writePassword() {

  //prompt that asks for user to enter correct password length
  var passwordLength = window.prompt( "Please enter a password length between 8 and 128 characters.");
      if(passwordLength >= 8 || passwordLength <= 128){
        console.log(passwordLength);
        window.confirm("hit 'Okay' to confirm if you want your password to be this length.");
      }else{
        alert("Please enter a password length between 8 and 128 characters.")
      }
      //requirement for password to have upper case charachter
  var upperConfirm = window.prompt( "Please enter a password that contains an Upper case Character");
      for (var i = 0; i < upper.length; i++){
        console.log()
      }



    
  var password = generatePassword();
  var passwordText = document.querySelector("#password");

  passwordText.value = password; 

}

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

0

Just remove the for loop and use the test method like so

if (/[A-Z]/g.test(upperConfirm) ){
    // includes an uppercase character password
}else{
    alert("Please enter a password that has an uppercase character.")
}
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!