Second question after making changes
Ok. I've changed a few things to reduce confusion and added alert for invalid user input. The code still is not working and not quite sure why.
function generatePassword() {
var uppercaseArray = ["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 lowercaseArray = ["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 numbArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
var characterArray = ["@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+"];
var resultArray = [];
var userArray = [];
uppercaseArray [1]
//-----------------------------------------------------------------
var numCharacter = prompt ("How many number of Characters do you want in your password? (You can pick between 8 and 128)");
var numbers = confirm ("you want numbers in your password?");
var uppercases = confirm ("you want Uppercases in your password?");
var lowercases = confirm ("you want lowercases in your password?");
var characters = confirm ("you want special characters in your password?");
if(numCharacter < 8 || numCharacter > 128) {
if (numbers){
resultArray = resultArray.concat(numbArray);
}
if (uppercases){
resultArray = resultArray.concat(uppercaseArray);
}
if (lowercases){
resultArray = resultArray.concat(lowercaseArray);
}
if (characters){
resultArray = resultArray.concat(characterArray);
}
console.log(resultArray)
for (var i = 0; i < numCharacter; i++) {
userArray.push (resultArray[Math.floor(Math.random() * resultArray.length)]);
}
return userArray.join("") ;
}
}else{
alert("Please pick numbers between 8 and 128.");
}
Initial question
I'm trying to give a prompt window to the users when 'generate password' button is clicked then if the user input is invalid (not between 8 to 128) I want to pop alert window saying 'Please pick between 8 and 128'. When I add if (numCharacter => "8" || numCharacter => "128") function stops working for some reason. Could anyone tell me what went wrong?
Aucun commentaire:
Enregistrer un commentaire