-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
36 lines (30 loc) · 998 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$('button').on('click', function(e) {
e.preventDefault();
var namespergroup = parseInt($('.pergroup').val()),
allnames = $('textarea').val().split('\n'),
allnameslen = allnames.length;
var numgroups = Math.ceil(allnameslen / namespergroup);
if($('.numgroups').val()){
numgroups = parseInt($('.numgroups').val());
namespergroup = allnameslen / numgroups;
}
$('.groups').empty();
for (i = 0; i < numgroups; i++) {
$('.groups').append('<div class="group" id="group' + (i+1) + '"><h2>Group ' + (i+1) + '</h2></div>');
}
$('.group').each(function() {
for (j = 0; j < namespergroup; j++) {
var randname = Math.floor(Math.random() * allnames.length);
if(allnames[randname]){
$(this).append('<p>' + allnames[randname] + '</p>');
}
allnames.splice(randname, 1);
console.log(allnames);
}
});
});
$('.toggle-wrap a').on('click', function(e){
e.preventDefault();
$('.wrap').toggleClass('alt');
$('.pergroup-wrap, .numgroups-wrap').find('input').val('');
});