Quite a bit going on here, but has some basic errors.
I have fixed those errors so that it creates a password when first run, and when you click the generate button thereafter.
let password = ["NyiNE7!38vs","SyiMA4*78dt","SuoSO6]40db","LeaDU9'11ln","QooGU9!09nk","SeuXI1_63sp","SieKY6)07zk","GaaDI9'30gn","BoyLY4|74ct","BuaZI0+69vl"]
// returns a random numbr;
function Random() {
let i = Math.floor(Math.random() * 9)
return i; // note i return the random number!
}
// returns a new password using Random()
function newPw(){
return password[Random()];
}
const div = document.getElementById('password')
const button = document.getElementById('generate')
button.addEventListener('click' , generatePassword)
// if you want a pre-populated password;
generatePassword();
// Sets a new random password
function generatePassword(){
div.innerHTML = newPw();
}
I have shortened this down to use a far more secure method of generating passwords, you can find plenty of examples of random password generators on SO.
const div = document.getElementById('password')
const button = document.getElementById('generate')
button.addEventListener('click' , generatePassword);
// if you want a pre-populated password;
generatePassword();
// taken from https://stackoverflow.com/questions/9719570/generate-random-password-string-with-requirements-in-javascript
function generatePassword(){
var randPassword = Array(10).fill("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").map(function(x) { return x[Math.floor(Math.random() * x.length)] }).join('');var randPassword = Array(10).fill("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").map(function(x) { return x[Math.floor(Math.random() * x.length)] }).join('');
div.innerHTML = randPassword;
}