I did random password generator and it works fine but sometimes when I roll for new pass there is undefined inside var text in console. How to fix it?
function generate()
{
var tab = ['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'];
var text = [];
for (var i = 0; i < 10; i++) {
x = Math.random()*tab.length;
z = Math.round(x)
text.push(tab[z]);
}
console.log(text);
document.getElementById('input1').value = text.join('');
}
<!DOCTYPE html>
<html>
<script src="script.js"></script>
<link rel="stylesheet" href="style.css">
<head></head>
</head>
<body>
<div class="randompass">
<input id="input1"></input>
<button onclick="generate()">Create random</button>
</div>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire