I am doing a random generator in Javascript.
What doesen't work? I get the "undefined" value very often (~80% of all time) as the first value here in this script. If I make the array bigger, the error occures less often.
When will it work? If I make the both arrays with the same amount of entries, I don't get the error.
And if I swap the order in the code of * two.length);
with one.length);
it also works.
Can you spot the error? Its driving me crazy and its very strange.
var one =
['Abashed',
'Abhorrent',
'Party',
'Zing',
'Zip',
'Zippy'];
var two =
['Account',
'Wives',
'Wills',
'Wins',
'Wounds',
'Wrecks',
'Wrists',
'Writings',
'Wrongs',
'Years',
'Yellows',
'Young',
'Youths',
'Zings',
'Zips'];
function showrandom() {
var rand = Math.floor(Math.random() * one.length);
var rand = Math.floor(Math.random() * two.length);
document.getElementById('random').innerHTML = one[rand] + ' ' + two[rand];
}
showrandom();
Aucun commentaire:
Enregistrer un commentaire