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