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;
}
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.")
}