Guys i am trying to get random values when click a button and made that code but when i click somehow one value repeat itself 4 times like "k0k2k4k6" , "n0n2n4n6". Why this happenning?Cos its not a coincidence. Thanks in advance! JSFIDDLE
$(function() {
var words = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"
var word = words[Math.floor(Math.random() * words.length)];
var myLength = 8;
function random() {
for (var i = 0; i < myLength; i++) {
$('#content').append(word + i++);
}
}
$('#button').click(function() {
random();
});
});
#content {
width: 200px;
height: 50px;
border: 1px solid #333;
margin-top: 50px;
<script src="http://ift.tt/1oMJErh"></script>
<button id="button">Click</button>
<div id="content"></div>
Aucun commentaire:
Enregistrer un commentaire