-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (50 loc) · 1.87 KB
/
script.js
File metadata and controls
67 lines (50 loc) · 1.87 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
var upCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var lowCase = "abcdefghijklmnopqrstuvwxyz";
var numb = "1234567890";
var specChar = "!@#$%^&()',/\|`~{[}]*+=?><.-_";
var userSel = [];
var userPass = [];
// Assignment Code
var generateBtn = document.querySelector("#generate");
// Write password to the #password input
function writePassword() { // ask the user the length
let length = prompt("Choose the length of your password to be between 8 and 128 characters.");
if (length > 8 && length < 128) {
alert ("Great, just a few more questions.")
} else {
alert("Please make sure you enter at least a number above 8 and no greater then 128");
return;
}
console.log(length);
// ask the user the uppercase
let upperCharac = confirm("Would you like the password to have upper case letters?");
if (upperCharac) {
userSel.push(... upCase);
}
console.log(userSel);
// ask the user the lowercase
let lowerCharac = confirm("Would you like the password to have lower case letters?");
if (lowerCharac) {
userSel.push(... lowCase);
}
console.log(userSel);
// ask the user the special characters
let special = confirm("Would you like the password to have special characters?");
if (special) {
userSel.push(... specChar);
}
console.log(userSel);
// ask the user the numbers
let numbers = confirm("Would you like the password to have numbers?");
if (numbers) {
userSel.push(... numb);
}
console.log(userSel);
for (let i = 0; i < length; i++) {
userPass.push(userSel[Math.floor(Math.random() * userSel.length)]);
console.log(userPass.join("+"));
}
var passwordText = document.querySelector("#password");
passwordText.value = userPass.join("");
}
generateBtn.addEventListener("click", writePassword);