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
Because you should obtain the letter every time, but you do it just once.
var emptyString = "";
var alphabet = "abcdefghijklmnopqrstuvwxyz";
while (emptyString.length < 6) {
emptyString += alphabet[Math.floor(Math.random() * alphabet.length)];
}
console.log(emptyString);
Also, not sure what you wanted to achieve with emptyString++
, removing that, since ++
is the "increment by one" operator and you can't incremenent a string. I think the purpose was to have it as a counter for that while loop, but it's needless, since the counter is the string length already.