-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5 Password Generator JS.js
More file actions
71 lines (56 loc) · 1.56 KB
/
5 Password Generator JS.js
File metadata and controls
71 lines (56 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let letters = [];
for (let i = 97; i < 123; i++) {
letters.push(String.fromCharCode(i));
}
for (let i = 65; i < 91; i++){
letters.push(String.fromCharCode(i));
}
let symbols = [];
for (let i = 33; i < 48; i++) {
symbols.push(String.fromCharCode(i));
}
for (let i = 58; i < 65; i++) {
symbols.push(String.fromCharCode(i));
}
for (let i = 91; i < 97; i++) {
symbols.push(String.fromCharCode(i));
}
for (let i = 123; i < 127; i++) {
symbols.push(String.fromCharCode(i));
}
let nums = [];
for (let i = 48; i < 58; i++) {
nums.push(String.fromCharCode(i));
}
console.log(`Welcome to the Password Generator!`)
let numLetters = Number(prompt(`How many letters would you like in your password?`))
let numSymbols = Number(prompt(`How many symbols?`))
let numNumbers = Number(prompt(`How many numbers?`))
let passwordList = [];
function shuffle(array){
let currentIndex = array.length;
while (currentIndex != 0){
let randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
}
}
for (let i = 0; i < numLetters; i++){
shuffle(letters);
passwordList.push(letters[i]);
}
for (let i = 0; i < numSymbols; i++){
shuffle(symbols);
passwordList.push(symbols[i]);
}
for ( let i = 0; i < numNumbers; i++){
shuffle(nums);
passwordList.push(nums[i]);
}
shuffle(passwordList);
let password = "";
for (let i = 0; i < passwordList.length; i++){
password += passwordList[i]
}
console.log(`Your password:
${password}`)