I’m working on the password generator & checker. I already filled in the first step. I stuck on the last step. I need to export “generatePassword and checkPassword functions”. Here is the instructions. And the HTML page and JavaScript.
Create a function called checkPassword()
that takes password
as a parameter. Inside the checkPassword()
function, if the length of password
is less than 6, throw a new error with the message: 'Password is too short! Generate another password.'
.
Lastly, export the generatePassword()
and checkPassword()
functions at the bottom of the code.
If the code works correctly, clicking on the “Generate Password” button should generate a password with a length of 4 to 8 digits. If the generated password length is less than 6, the error message will be displayed.
----HTML----
CCA body{ font-family: 'Helvetica', san-serif; text-align: center; } #password{ font-weight: bold; } #warning{ color: #cd5c5c }Password Generator & Checker
----JavaScript----
const generatePassword = () => {
let passwordLength = Math.floor(Math.random() * 5 + 4);
let generatedPassword = Math.floor(Math.random() * Math.pow(10, passwordLength));
return generatedPassword.toString();
}
// add a checkPassword function that throws an error when password length is less than 6
let string = “”;
For(let i=0; < passwordLength; i++){
let number = Math.floor(Math.random() * 9);
string += number.toString();
}
Return string;
if(string.length < 6){
return “error”;
}
// export generatePassword and checkPassword functions