Build a Password Generator App - Build a Password Generator App

Tell us what’s happening:

I am having issues passing the following two test cases:
4. Your function should return a randomly generated password with valid characters. 9. You should call the generatePassword function with a numeric argument and store the returned password in the password variable.

Your code so far

function generatePassword(passwordLength) {
  // ASCII Range (0 - 128)
  const min = 33; // Skip over control characters AND the space character due to test case issues
  const max = 128 + 1; 

  const arrayChar = [];
  const alteredArr = [];

  for (let i = 0; i < passwordLength; i++) {
    arrayChar.push(Math.floor(Math.random() * (max - min) + min));
  }

  for (const element of arrayChar) {
    alteredArr.push(String.fromCharCode(element));
  }

  const passwordString = alteredArr.join("");

  // #### DEBUGGING ####
  /* console.log("Decimal Array: " + arrayChar);
  console.log("ASCII Array: " + alteredArr);
  console.log("Random Generated Password: " + passwordString); */

  return passwordString;
}

const password = generatePassword(10);
console.log("Generated password: " + password);

The randomly generated password generates valid characters and I am assigning it to the password variable after having used a numeric argument. So, I am unsure what I am doing wrong here.

My console output:

Generated password: 2sw,5YUD}

Challenge Information:

Build a Password Generator App - Build a Password Generator App

hi, i’ve tried your code and it generates space/spaces in the generated password and space is not a valid character in password generated
i hope that help

1 Like

Yeah, I realized that too. I searched up the ASCII list and it says 32 represents a space character, so I excluded it from the range of randomly generated characters. However, it still prints it out for some reason.

i think you try a very complicated method to solve it, i could give you a small hint may shorten the path to you,

instead of generating the unicode of the chars you can make a variable with the valid chars and pass it in a string

1 Like

That worked, thank you! I also managed to overlook it showed what valid characters to use in the Lab description.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.