-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (42 loc) · 1.57 KB
/
script.js
File metadata and controls
56 lines (42 loc) · 1.57 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
// Assignment Code
var generateBtn = document.querySelector("#generate");
// Write password to the #password input
function writePassword() {
var password = generatePassword();
var passwordText = document.querySelector("#password");
passwordText.value = password;
}
function generatePassword() {
var howLong = Number(
prompt("Enter a number for how long you would like your password to be?")
);
var values = "ABCDEFGHIJKLMNOPQRSTUCWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()+|?/.,:'><[{]}`~";
// if statement to validate user input in howLong variable
if(howLong < 8){
alert("Password must be longer than 8 characters.");
return "";
} else if(howLong > 129){
alert("Password cannot be greater than 129 Characters");
return "";
}else{
var confirmUpperCase = confirm(
"Click OK to confirm the use of upper case letters."
);
var confirmLowerCase = confirm(
"Click OK to confirm the use of lowercase letters."
);
var confirmNumbers = confirm("Click OK to confirm the use of whole numbers.");
var confirmCharacters = confirm(
"Click OK to confirm the use of special characters."
);
// variable to be used to return value of for loop
var retVal = "";
for (var i = 0; i < howLong; i++) {
// picks random characters from the "values" variables beginning at index of a random number
retVal += values.charAt(Math.floor(Math.random() * values.length));
}
}
return retVal;
}
// Add event listener to generate button
generateBtn.addEventListener("click", writePassword);