jeudi 4 août 2016

javascript password generator not working

Recently I started a new project (random password generator) in javascript and something isn't working its not finished yet. (Im just a beginner in js)

Here is the HTML:

<!DOCTYPE HTML>
<html>
   <head>
      <meta charset='utf-8'>
      <title>Random Password</title>
      <link href='main.css' rel='stylesheet'>
      <script src='ui.js'></script>
   </head>
   <body>
      <div class='container'>
         <input type='checkbox' class='check' value='uppercase'> uppercase letters <br />
         <input type='checkbox' class='check' value='lowercase'> lowercase letters <br />
         <input type='checkbox' class='check' value='number'> numbers <br />
         <input type='checkbox' class='check' value='symbol'> symbols <br />
         <input type='number' id='length' value='length'><br /><br />
         <input type='button' id='generate' value='generate' onclick="getvalues()">
      </div>
   </body>
</html>

And thats the js:

var uppercase_letters = ['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'];
var lowercase_letters = ['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'];
var numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
var symbols = ['/', '[', ']', '$', '-', ':', '_', '?', '{', '}', '~', '!', '@', '#', '%', '&', '*', '(', ')', '"', '^', '§', ',', '.', '°', '+', '-', ':'];
var length;
//--------------------
var check1;
var check2;
var check3;
var check4;
var inputnum;

function getvalues(){
   inputnum = document.getElementById("length").value;
   length = inputnum;
   check1 = document.getElementsByClassName("check")[1];
   check2 = document.getElementsByClassName("check")[2];
   check3 = document.getElementsByClassName("check")[3];
   check4 = document.getElementsByClassName("check")[4];
   generatestring();
}

function generatestring(){
var string;

   if(check1.checked === true){string = string.concat(uppercase_letters)};

   if(check2.checked === true){string = string.concat(lowercase_letters)};

   if(check3.checked === true){string = string.concat(numbers)};

   if(check4.checked === true){string = string.concat(symbols)};

alert("Working?");
show(string);
}

function show(string){
   alert(string);
}

So, the alert with the string (just for testing) isn't showing up, thats why i added the one with the message "Working?", and this one isn't showing up as well. I have no idea why... I am sure that the problem are these "if's" but i don't know how to do it in another way :( Could someone please help me out?

Probably I am doing everything completly wrong, so please give me some tipps.

Thank you!

Aucun commentaire:

Enregistrer un commentaire