JavaScript Password Generator

How to Build a Password Generator with Vanilla JavaScript

html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./main.js" defer></script>
    <title>Password Generator</title>
</head>

<body>
    <span>Generate password:</span>
    <input id="passwordInput" type="text">
    <button onclick="generatePassword()">Generate password</button>
</body>

</html>

javascript

const input = document.getElementById('passwordInput');
let password = "";

function generatePassword() {

    if (password.length != 16) {
        const letters = "abcdefghimnlopqrstuvwxyz-0123456789-[]{}!#$%&/()=?ยก*";
        const randomIndex = Math.floor(Math.random() * letters.length);
        const randomLetter = letters[randomIndex];
        password += randomLetter;
        generatePassword();
    } else {
        input.value = password;
        password = "";
    }
}