You can view the live site here: www.theladeli.github.io/password-generator
- First I created the JS code for it (saving the values to variables and logging it to console)
- Next I created the basic HTML for it
- Styled it up using CSS
- Added Copy & Refresh buttons
- Made the site mobile responsive
I wanted the site to be simple with no excess content.
- Created a heading of "Password Generator"
- Created a
<p>
in adiv
withcontenteditable
set totrue
- Created two columns below, one with a button for Copy the other for Refresh
- Set the Copy buttons
onclick
event to call thecopyToClipboard
function - Set the Refresh buttons
onclick
event to reload the page - Added Font Awesome's
script
- Linked my
index.js
script
I'm sure there are many better methods to do it than the way I did, but here's what I did:
- Created an array called
characters
with a list of characters available in the password (all letters in the alphabet, all letters in the capitalized version, numbers and common symbols) - Next I created a variable called
length
to get a random length of the password, a minimum of 8 characters. I usedMath.random()
rounded down times by 14, plus eight (for the minimum) - I created an empty array called
password
- Inside a
for
loop, using anotherMath.random()
number set up to the length of thecharacters
array, I pushed the character at the random numbers position into the emptypassword
array I created earlier - I had the
for
loop run untili => length
- I created a variable called
strongPass
and using thejoin
method, concactinated thepassword
array into a string with no seperator - Using DOM I targeted the
<p>
element on the page where I wanted the generated password to display and set theinnerHTML
to thestrongPass
variable - Created a
copyToClipboard
function that writes to clipboard thestrongPass
variable, and displays analert
after doing so