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

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

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