let generatorButton = document.getElementById("generator");
generatorButton.addEventListener("click", () => {
let passwordLength = 16;
let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_";
let password = "";
for (i = 0;i < passwordLength;i++){
password = password + characters.charAt(Math.floor(Math.random() * Math.floor(characters.length - 1)));
}
document.getElementById("textField").value = password;
});
:root {
--gray: #CBC4C4;
--blue: #029DF1;
--white: #FFF;
}
* {
font-family: Roboto, sas-serif;
margin: 0;
padding: 0;
margin-top: 15px;
}
body {
background: var(--blue);
}
.container {
width: 300px;
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: var(--gray);
font-size: large;
border-radius: 30px;
}
button {
background: var(--blue);
color: var(--white);
padding: 20px 20px;
margin: 10px 5px;
font-size: large;
cursor: pointer;
}
button:focus {
border: 2px solid var(--blue);
outline: none;
}
input {
font-size: large;
border: 3px solid var(--blue);
outline: none;
margin-bottom: 15px;
}
input::placeholder {
opacity: 0.6;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Password Generator</title>
</head>
<body>
<div class="container">
<h2>Password Generator</h2>
<button id="generator">Generate!</button>
<input type="text" id="textField" placeholder="Your password goes here...">
</div>
<script src="script.js"></script>
</body>
</html>
I could add a few things onto this, like having a way to copy onto the clipboard and such. But really what I want to know is, how can I make this code shorter and more efficient? Specifically, my CSS is long. Maybe I should start using a CSS framework? Let me know.