password generator
by Евгений
HTML
<input id=input type=text placeholder="pattern here" value="xxxxxx0X">
<button id=generate type=button>Generate</button>
<button id=copy type=button>Copy</button>
<span id=msg></span>
CSS
input, button {
font-size: 16px;
}
JavaScript
const letters = 'abcdefghijklmnopqrstuvwxyz';
const input = document.querySelector('#input');
const copyBtn = document.querySelector('#copy');
const generateBtn = document.querySelector('#generate');
const msg = document.querySelector('#msg');
const randomLetter = _ => letters.charAt(Math.floor(Math.random() * letters.length));
const randomLetterUpper = _ => randomLetter().toUpperCase();
const randomNumber = _ => Math.ceil(Math.random() * 9) ;
const getPass = pattern => pattern
.replace(/[a-z]/g, randomLetter)
.replace(/\d/g, randomNumber)
.replace(/[A-Z]/g, randomLetterUpper);
const copyPass = _ => {
input.select();
document.execCommand('Copy');
msg.textContent = 'Copied';
setTimeout(_ => msg.textContent = '', 2000);
}
generateBtn.addEventListener('click', _ => input.value = getPass(input.value));
copyBtn.addEventListener('click',copyPass );