I am trying to reprompt the user if the password length is less than 8 or greater than 128 characters. the condition for less than eight is working but the last condition in the while loop is not working properly. What am I doing wrong?
let askUser;
// create a function for prompts
const prompts = () => {
const minLength = 8;
const maxLength = 128;
askUser = prompt('Enter a password character length. Character length must be at least 8 and between 128.');
while (askUser < minLength || askUser === null || askUser > maxLength) {
// ask the user again
askUser = prompt('Enter a password character length. Character length must be at least 8 and between 128.');
let confirmSpecialCharacter;
// if password is between length range
if (askUser >= minLength && askUser <= maxLength) {
// ask for special characters
confirmSpecialCharacter = confirm('Would you like for your password to include special characters?');
// if yes, call combine random
if (confirmSpecialCharacter === 'yes') {
let pass = combineRandom();
alert(pass);
} else {
let pass = noSpecialCharacters();
alert(pass);
}
}
}
return askUser;
}
Aucun commentaire:
Enregistrer un commentaire