script.js
// Write password to the #password input
Write password to the #password input
Write password to the #password input
function generatePassword() {
    var passwordLength = prompt(
        "how many characters would you like your password to contain?"
    );
    console.log(passwordLength);
    if (parseInt(passwordLength) < 8 || parseInt(passwordLength) > 128) {
        alert(
            "password length must be at least 8 characters or less than 128 characters"
        );
    } else {
        var hasNumber = confirm("Click OK to confirm including numbers");
        if (hasNumber) {
            allCharacters = allCharacters.concat(numericCharacters);
            console.log(allCharacters);
            console.log("yes to numbers");
        } else if (!hasNumber) {
            console.log("no to numbers");
        }
        console.log("it worked");
        var hasSpecialCharacters = confirm(
            "Click OK to confirm special characters"
        );
        if (hasSpecialCharacters) {
            allCharacters = allCharacters.concat(specialCharacters);
            console.log(allCharacters);
            console.log("yes to special characters");
        } else if (!hasSpecialCharacters) {
            console.log("no to special characters");
        }
        var hasUpperCasedCharacters = confirm("Click OK to confirm uppercase");
        if (hasUpperCasedCharacters) {
            allCharacters = allCharacters.concat(upperCasedCharacters);
            console.log(allCharacters);
            console.log("yes to upper case");
        } else if (!hasUpperCasedCharacters) {
            console.log("no to upper case");
        }
        var haslowerCasedCharacters = confirm("Click OK to confirm lowercase");
        if (haslowerCasedCharacters) {
            allCharacters = allCharacters.concat(lowerCasedCharacters);
            console.log(allCharacters);
            console.log("yes to lower case");
        } else if (!haslowerCasedCharacters) {
            console.log("no to lower case");
        }
        if (
            haslowerCasedCharacters === false &&
            hasUpperCasedCharacters === false &&
            ((hasSpecialCharacters === false) === hasNumber) === false
        ) {
            alert("Select at least one type");
            generatePassword();
        } else console.log("valid options chosen");
    }
    let password = ".";
    for (let i = 0; i < passwordLength; i++) {
        password += allCharacters[Math.floor(Math.random() * allCharacters.length)];
    }
    return password;
}
function generatePassword ( ) { var passwordLength = prompt ( "how many characters would you like your password to contain?" ) ; console . log ( passwordLength ) ; if ( parseInt ( passwordLength ) < 8 || parseInt ( passwordLength ) > 128 ) { alert ( "password length must be at least 8 characters or less than 128 characters" ) ; } else { var hasNumber = confirm ( "Click OK to confirm including numbers" ) ; if ( hasNumber ) { allCharacters = allCharacters . concat ( numericCharacters ) ; console . log ( allCharacters ) ; console . log ( "yes to numbers" ) ; } else if ( ! hasNumber ) { console . log ( "no to numbers" ) ; } console . log ( "it worked" ) ; var hasSpecialCharacters = confirm ( "Click OK to confirm special characters" ) ; if ( hasSpecialCharacters ) { allCharacters = allCharacters . concat ( specialCharacters ) ; console . log ( allCharacters ) ; console . log ( "yes to special characters" ) ; } else if ( ! hasSpecialCharacters ) { console . log ( "no to special characters" ) ; } var hasUpperCasedCharacters = confirm ( "Click OK to confirm uppercase" ) ; if ( hasUpperCasedCharacters ) { allCharacters = allCharacters . concat ( upperCasedCharacters ) ; console . log ( allCharacters ) ; console . log ( "yes to upper case" ) ; } else if ( ! hasUpperCasedCharacters ) { console . log ( "no to upper case" ) ; } var haslowerCasedCharacters = confirm ( "Click OK to confirm lowercase" ) ; if ( haslowerCasedCharacters ) { allCharacters = allCharacters . concat ( lowerCasedCharacters ) ; console . log ( allCharacters ) ; console . log ( "yes to lower case" ) ; } else if ( ! haslowerCasedCharacters ) { console . log ( "no to lower case" ) ; } if ( haslowerCasedCharacters === false && hasUpperCasedCharacters === false && ( ( hasSpecialCharacters === false ) === hasNumber ) === false ) { alert ( "Select at least one type" ) ; generatePassword ( ) ; } else console . log ( "valid options chosen" ) ; } let password = "." ; for ( let i = 0 ; i < passwordLength ; i ++ ) { password += allCharacters [ Math . floor ( Math . random ( ) * allCharacters . length ) ] ; } return password ; }
Write password to the #password input
Write password to the #password input
//password length query //numbers query //special characters query //uppercase query //lowercase query //selecting random characters