I am new to javaScript and having a terrible time with understanding loops. Currently I have a random text generator function. I have gotten it to generate random characters from a string but only one character each time the function is ran. I would like to build a string of 20 random characters from the output of the function.
This is what I have so far:
function passGen() {
let text = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVVWYXZ()!@#$%&*/?+-%".split("");
let randomIndex = Math.floor(Math.random() * text.length);
return text[randomIndex];
}
let randomPass = passGen();
I would like to let the function produce the random character and then use a for loop to out put 20 of these random characters in a string.
I can't get
for (let i = 0; i <= 20; i++){
console.log(randomPass)
to work.
Any help is appreciated.