Hey was wondering if anyone would be able to help me figure out where I went wrong in this code. I am very new to coding so sorry if it is a little wonky. Very open to any feedback! I am trying to make a password generator that prompts you asking how many characters in total and which characters to include.
The function worked when I logged it but adding it to the button to generate when you click it kinda went a little downhill.
Also not as important but in my prompting I can't figure out how to get the else statement to restart the process if they put a number outside the parameters.
var spec = '!@$%^&*()_+';
var low = 'abcdefghijklmnopqrstuvwxyz';
var num = '0123456789';
var upp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var charLength = prompt("How many characters between 8 - 128?");
if (charLength >= 8, charLength <= 128) {
var lowChar = confirm("Include lowercase letters?");
var upChar = confirm("Include uppercase letters?");
var specChar = confirm("Include special characters?");
var numChar = confirm("Include numbers?");
}
else {
var charLength = prompt("How many characters between 8 - 128?");
};
var passwords = document.getElementById("password");
var generate = document.getElementById("btnGen");
var copy = document.getElementById("btnCopy");
generate.addEventListener("click", function(){
var character = '';
lowChar ? characters += low : '';
upChar ? characters += upp : '';
specChar ? characters += spec : '';
numChar ? characters += num : '';
passwords.value = password(charLength.value, characters)
});
function password(l, characters){
var pwd = '';
for(var i = 0; i < l; i++){
pwd += characters.charAt(Math.floor(Math.random() * characters.length))
}
return pwd;
}
Thank You!
Aucun commentaire:
Enregistrer un commentaire