So, the assignment is generating a random password between 7-10 characters. Is this valid syntax in my for loop which generates the amount of numbers.
var password = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789@#$";
for (i = 1; i <= 10; i++) {
var char = Math.floor(Math.random() * characters.length + 1);
password += characters.charAt(char);
}
console.log(password);
So, this current for loop makes the password ten characters. I want it to be between 7 and 10 characters. Is it valid Javascript syntax to do i<=10 && i>=7?
What you can do is select a random number from 0 to 3. Based on that number, you will decide how long your password is. Could be 7+0 or 7+1 or 7+2 or 7+3.
Now the number of times your loop runs is dynamic and hence you will get passwords of different lengths.
var password = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789@#$";
let x = Math.floor(Math.random()*4);
for (i = 1; i <= (7+x); i++) {
var char = Math.floor(Math.random() * characters.length + 1);
password += characters.charAt(char);
}
console.log(password);