-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (36 loc) · 1.59 KB
/
index.js
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
// javascript
const characters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","~","`","!","@","#","$","%","^","&","*","(",")","_","-","+","=","{","[","}","]",",","|",":",";","<",">",".","?",
"/"];
let passwordElOne = document.getElementById("password-el-one")
let passwordElTwo = document.getElementById("password-el-two")
const btnGenerator = document.getElementById("btn-generator")
let inputEl = document.getElementById("input-el")
let passwordOne = null
let passwordTwo = null
btnGenerator.addEventListener("click", function () {
generate()
})
function generate() {
let listOne = []
let listTwo = []
passwordElOne.textContent = null
passwordElTwo.textContent = null
for (let i = 0; i < characters.length; i++){
passwordOne = Math.floor(Math.random() * characters.length)
passwordTwo = Math.floor(Math.random() * characters.length)
let charOne = characters[passwordOne]
let charTwo = characters[passwordTwo]
if (listOne.length < inputEl.value ){
listOne.push(charOne)
}
if (listTwo.length < inputEl.value){
listTwo.push(charTwo)
}
}
for (let i = 0; i < listOne.length; i++){
passwordElOne.textContent += listOne[i]
}
for (let i = 0; i < listTwo.length; i++){
passwordElTwo.textContent += listTwo[i]
}
}