-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomGroupGenerator.html
More file actions
executable file
·184 lines (123 loc) · 3.88 KB
/
Copy pathRandomGroupGenerator.html
File metadata and controls
executable file
·184 lines (123 loc) · 3.88 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!DOCTYPE html>
<html>
<head>
<!-- <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body {
font-family: sans-serif;
background: #97a7d4;
}
h2 {
margin: 5px 0;
}
#wrapper {
width: 600px;
margin: 0 auto;
background: white;
padding: 10px 15px;
border-radius: 10px;
}
table, td {
border: 2px solid black;
}
.button {
background-color: #d3d3d3; /* Green */
border: none;
color: rgb(0, 0, 0);
padding: 6px 18px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
transition-duration: 0.4s;
cursor: pointer;
}
.button:hover {
background-color: #959695;
color: rgb(3, 3, 3);
}
.center {
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div id="wrapper">
<label for="numG">How many groups do you want to generate?</label><br>
<input type="text" id="numG" name="numG" ><br>
<button onclick ="confirmFuc();" type="button" class = "button" id="confirm">Confirm</button>
<button onclick ="resetFuc();" type="button" class = "button" id="reset">Reset</button>
<script>
var student_name =
"Apple Zeng\n"+
"Mango Wu\n"+
"Pear Zhang\n"+
"Avacado Gao\n"+
"Potato Han\n"+
"Banana Chen\n"+
"Tomato Li\n"
var class_array =[];
var lines = student_name.split('\n');
for(var i= 0; i < lines.length-1; i++){
var curr_line = lines[i];
var person = {sName: curr_line,sNumber: i,sGroup:0}
class_array.push(person)
console.log("xue"+person.sName)
}
console.log(class_array)
function confirmFuc(){
var groupN = document.getElementById("numG").value;
var groupnumber = parseInt(groupN)
shuffle(class_array)
//console.log(class_array)
for(var i= 0; i < class_array.length; i++){
var x = i%groupnumber
var curr = class_array[i]
console.log("group"+x)
curr.sGroup =x;
}
//console.log(class_array)
generator()
}
function generator() {
var xtable = document.createElement("TABLE");
xtable.setAttribute("id", "myTable");
xtable.setAttribute("class", "center");
document.body.appendChild(xtable);
for(var i= 0; i < class_array.length; i++){
var rownum = class_array[i].sGroup
var y = document.createElement("TD");
y.setAttribute("id", "myTD"+rownum);
document.getElementById("myTable").appendChild(y);
var z = document.createElement("TR");
var t = document.createTextNode(class_array[i].sGroup+1);
z.appendChild(t);
document.getElementById("myTD"+rownum).appendChild(z);
var namestudent = document.createTextNode(class_array[i].sName);
z.appendChild(namestudent);
document.getElementById("myTD"+rownum).appendChild(z);
}
}
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
function resetFuc(){
var Table = document.getElementById("myTable");
Table.innerHTML = "";
}
</script>
</body>
</html>