-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroupnaidee.js
86 lines (72 loc) · 2.24 KB
/
groupnaidee.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
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
inputArray = []
teamOne = []
teamTwo = []
teamThree = []
teamFour =[]
allTeam = [teamOne,teamTwo,teamThree,teamFour]
//
function fn(){
let textInput = document.getElementById("textInput").value
let inputSplit = textInput.split(",")
//Add item to inputArray
for(let i=0;i<inputSplit.length;i++){
inputArray.push(inputSplit[i])
}
let len = inputArray.length
// Check radio button
if(document.getElementById("2team").checked){
if(inputSplit.length > 8){
alert("You choosed 2 teams, Maximum 8 items ")
inputArray = []
return false;
}
else{
add(len,2)
}
}
else if(document.getElementById("3team").checked){
if(inputSplit.length > 12){
alert("You choosed 3 teams, Maximum 12 items ")
inputArray = []
return false;
}
else{
add(len,3)
}
}
else if(document.getElementById("4team").checked){
if(inputSplit.length > 16){
alert("You choosed 4 teams, Maximum 16 items ")
inputArray = []
return false;
}
else{
add(len,4)
}
}
}
function add(len,numOfTeam){
outputTeamOne = document.getElementById("teamOne")
outputTeamTwo = document.getElementById("teamTwo")
outputTeamThree = document.getElementById("teamThree")
outputTeamFour = document.getElementById("teamFour")
inputAllTeam = [outputTeamOne,outputTeamTwo,outputTeamThree,outputTeamFour]
outputTeamOne.innerHTML = ''
outputTeamTwo.innerHTML = ''
outputTeamThree.innerHTML = ''
outputTeamFour.innerHTML = ''
for(let k=0;k<(len/numOfTeam);k++){
for(let l=0;l<numOfTeam;l++){
//add to team three array
randomIndex = Math.floor(Math.random() * inputArray.length);
//add item to team box
inputAllTeam[l].innerHTML = inputAllTeam[l].innerHTML + "<p>" + inputArray[randomIndex] +"</p>"
// delete inputArray[randomIndex]
inputArray.splice(randomIndex,1)
if(inputArray.length === 0){
break
}
}
}
}
//a,s,d,f,g,h,j,k,z,x,c,v,b,n