I am a student who still needs to study a lot.
I want to make random arrangement between 1-12, and I have twelve contents, so I tried to give them numbers randomly (1-12).
so I tried this for random number:
function getRandom(min, max) {
return Math.floor((Math.random() * (max - min + 1)) + min);
}
function getRandomArray(min, max, count) {
if (max - min + 1 < count) return;
var rdm = [];
while (1) {
var index = getRandom(min, max);
if (rdm.indexOf(index) > -1) {
continue;
}
rdm.push(index);
if (rdm.length == count) {
break;
}
}
return rdm
}
and got random numbers (of 12)...
getRandomArray(1, 12, 12)
and give class name... but It wouldn't work the way I thought.
var contentNumber = [getRandomArray(1, 12, 12)];
$content.eq(0).addClass(contentNumber[0]);
$content.eq(1).addClass(contentNumber[1]);
...
$content.eq(11).addClass(contentNumber[11]);
I thought it could be an 'Array' but it was just a bunch of numbers. Can I make this an Array?
Or maybe I have to change my initial expectation of it...