i try to build a function that should output x-amounts of ids with a y-lenght. The amount of Ids and length of Ids shall be input from the user through prompt.
Here is what i have tried so far:
function userIdGenerator() {
let amountOfId = prompt('Please enter the amount of IDs')
let lengthOfId = prompt('Please enter the lenght of your ID(s)')
let userId = ''
let userIds = []
let stringValues ='ABCDEFGHIJKLMNOabcdefghijklmnopqrstuvwxyzPQRSTUVWXYZ0123456789'
let numOfChar = stringValues.length
for(let i = 0; i < amountOfId; i++){
for(let i = 0; i < lengthOfId; i++){
if( i< lengthOfId ){
userId += stringValues.charAt(Math.round(Math.random() * numOfChar))
}else{
userIds.push(userId)
}
}
}
console.log(userIds)
}
I get an empty array as output. When i delete the else-statement and console.log(userId) i get a string that has the lenght of x*y so i wander how i can improve this function.
Thanks for help,
Willy