I'm completely new to JavaScript. I'm trying to allow users to select certain criteria for the password they would like to generate. I've made it so that if the user selects yes to certain password criteria, it is concat into another empty array. How should I go about creating a for loop that utilizes Math.random and other means of shuffling content of an array to generate and spit out what they have selected based on length of password and character type selected by the user? I've been agonizing over this for days and I can not figure it out.
var selectedNumbers = window.confirm("Password should contain numbers?");
var selectedLowerCase = window.confirm("Password should contain lowercase letters?");
var selectedUpperCase = window.confirm("Password should uppercase letters?");
var selectedSpecial = window.confirm("Password should contain special characters?");
if (selectedNumbers === true) {
characterOptionsList.concat(numbersList)
} else {
console.log(false);
}
if (selectedLowerCase === true) {
characterOptionsList.concat(lowerCaseList)
} else {
console.log(false);
}
if (selectedUpperCase === true) {
characterOptionsList.concat(upperCaseList)
} else {
console.log(false);
}
if (selectedSpecial === true) {
characterOptionsList.concat(specialList)
} else {
console.log(false);
}
}
I've already attempted a for loop, but it does absolutely nothing.
function writePassword() {
for (var i = 0; i > characterOptionsList.length; i++) {
const newPassword = Math.floor((characterOptionsList.length - start) * Math.random())
const randomArray = characterOptionsList.splice(randomPosition, 1)
randomArray.push(characterOptionsList);
return randomArray;
}
var password = generatePassword();
var passwordText = document.querySelector("#password");
passwordText.value = password
}
generateBtn.addEventListener("click", writePassword);
Here are the variables set for criteria arrays as well as the empty array they are to be concat inside of, if it's of any use to better understand what I'm trying to do.
var generateBtn = document.querySelector("#generate");
var numbersList = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9",];
var lowerCaseList = ["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 upperCaseList = ["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 specialList = ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")",];
var characterOptionsList = []