Password Generator & Checker

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

Generate Password

----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

there are several syntax mistakes in your code
use a single quote, double, or backtick for storing string values
missing the i in for loop and for loop and return should be small case not Capitalize
I guess all of the programming syntax is in small cases.

you can’t access the passwordLength variable outside of the function because passwordLength is a block scope
brush up: Scope - MDN Web Docs Glossary: Definitions of Web-related terms | MDN

I fixed the answer for generatePassword. It worked very well.
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
const checkPassword = () => {
throw Error(‘Password is too short! Generate another password.’);
}
// export generatePassword and checkPassword functions
export {generatePassword, checkPassword};