Wanting to make my userDigits info do the same thing as my length info

I had posted something similar last night but my wording was just a wreck. I ended up figuring it out but now I am at the opposite. The code below is from a password generator I am working on for a javascript module. I am wanting to put my userDigits, userSpec, userLower, and userUpper var into the writePassword function just like I did with length above them. It must be a prompt, no checkbox and it must come back as valid if anything other than the letters y Y n N is typed in. I have gotten it most of the way a few different ways each time but it is like a rubix cube. I fix once part and mess up the other. I am looking to insert those measurements into the writePassword function one by one looping back only to themselves if invalid. I am brand new to javascript so it could be some small errors I am making. Also if it is big I am okay with rewriting anything. I just want to be functional and this is my very last step of a tough project! Looking to be pointed in the write direction!
code show write password function to end of file.

// Write password to the #password input
function writePassword() {

    let isValidLength = false;
    let promptText = "How long would you like your password to be? Please choose between 8 and 128 characters."
    while (!isValidLength){
      var length = window.prompt(promptText);
      if (parseInt(length).toString() !== 'NaN'){
           if (length >= 8 && length <= 128){
             isValidLength = true;
           } else {
               promptText = 'Invalid option. Please enter a number between 8 and 128.';


    var userDigits=prompt('Would you like to use numbers in your password? Type "Y" for yes or "N" for no.');

    var userSpec = window.prompt('Would you like to include special characters in your password? Type "Y" for yes or "N" for no');
    var userLower = window.prompt('Would you like to include lowercase letters in your password? Type "Y" for yes or "N" for no');
    var userUpper = window.prompt('Would you like to include uppercase letters in your password? Type "Y" for yes or "N" for no');

  var password = generatePassword(length, [allowedDigits, allowedSpecial, allowedLowerCase, allowedUpperCase]);
  var passwordText = document.querySelector("#password");

  passwordText.value = password;


// Add event listener to generate button
generateBtn.addEventListener("click", writePassword);

 *  @return an array of allowed character arrays

 function promptUser() {


Source: JavaSript – Stack Overflow

October 3, 2021
Category : News
Tags: javascript | user-input

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.