I've created a for loop with javascript/jquery, in order to assign a random number to each div class with the name ".choice". There are four div's in total. When I run the following code:
for (var i = 0; i < 4; i++) {
var random = Math.floor(Math.random() * 12);
var chess = $(".choice");
chess.attr({
"data-random": random
});
$(".choice").append(chess);
}
All divs return the same number, instead of each div .choice having a random number.
(P.S first question on the site, hope this question made sense. Thanks in advance.)