Code
<body onLoad="changeInt(3)">
<input type="text" onkeyUp="changeInt(this.value);" onkeyDown="changeInt(this.value);" value="3">
<b>dein resultat: </b>
<span id="result">
Warte...
</span>
</body>
<script>
var nInt = 3;
var abc = ['a','b','c','d','e','f','g','h','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z'];
function getRandom(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
function get_letter(ai, modus) {
if(ai > (abc.length-1)) {
return get_letter(ai-abc.length, modus);
}
return modus == 1 ? abc[ai] : abc[ai].toUpperCase();
}
function changeInt(ni) {
nInt = ni;
var strings = [];
for(var i = 1; i <= nInt; i++) {
modus = getRandom(1, 3);
strings.push(get_letter(getRandom(0, 10000), modus));
}
var result = '';
document.getElementById('result').innerHTML = 'Warte...';
strings.forEach(function(el, index, arr) {
result +=el;
});
document.getElementById('result').innerHTML = result;
}
</script>
Alles anzeigen