This question is different from Take random letters out from a string because I am not trying to remove anything from the string.
I\'m trying to pick a rand
Get the random character in a loop
In your example, you are obtaining random character from array only once hence there is no way you are going to get another random character in while loop
Also note that emptyString++
will cause result as NaN
as you are trying to post-increment the string
var emptyString = "";
var alphabet = "abcdefghijklmnopqrstuvwxyz";
while (emptyString.length < 6) {
emptyString += alphabet[Math.floor(Math.random() * alphabet.length)];
}
console.log(emptyString);
Another tip, alphabet.length
could be cached instead of asking for it every time in while