-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
157 lines (148 loc) · 4.71 KB
/
scripts.js
File metadata and controls
157 lines (148 loc) · 4.71 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
const arrOfPeople = [
{
id: 2,
name: "Charles Young",
age: 55,
skillSet: "welding",
placeBorn: "Omaha, Nebraska"
},
{
id: 3,
name: "Judy Twilight",
age: 35,
skillSet: "fishing",
placeBorn: "Louisville, Kentucky"
},
{
id: 4,
name: "Cynthia Doolittle",
age: 20,
skillSet: "tic tac toe",
placeBorn: "Pawnee, Texas"
},
{
id: 5,
name: "John Willouby",
age: 28,
skillSet: "pipe fitting",
placeBorn: "New York, New York"
},
{
id: 6,
name: "Stan Honest",
age: 20,
skillSet: "boom-a-rang throwing",
placeBorn: "Perth, Australia"
},
{
id: 7,
name: "Mia Watu",
age: 17,
skillSet: "acrobatics",
placeBorn: "Los Angeles, California"
},
{
id: 8,
name: "Walter Cole",
age: 32,
skillSet: "jump rope",
placeBorn: "New Orleans, Louisiana"
},
];
const listOfPlayers = []
const blueTeam = []
const redTeam = []
class Player {
constructor(id, name, canThrowBall, canDodgeBall, hasPaid, isHealthy, yearsExperience){
this.id = id;
this.name = name;
this.canThrowBall = canThrowBall;
this.canDodgeBall = canDodgeBall;
this.hasPaid = hasPaid;
this.isHealthy = isHealthy;
this.yearsExperience = yearsExperience;
};
};
class BlueTeammate {
constructor(id, name, teamColor, mascot){
this.id = id;
this.name = name;
this.teamColor = teamColor;
this.mascot = mascot;
};
};
class RedTeammate {
constructor(id, name, teamColor, mascot){
this.id = id;
this.name = name;
this.teamColor = teamColor;
this.mascot = mascot;
};
};
const listPeopleChoices = () => {
const listElement = document.getElementById('people')
arrOfPeople.map(person => {
const li = document.createElement("li")
const button = document.createElement("button")
button.innerHTML = "Choose Team"
button.addEventListener('click', function() {makePlayer(person.id)} )
li.appendChild(button)
li.appendChild(document.createTextNode(person.name + " - " + person.skillSet))
listElement.append(li)
});
let buttonDelete = document.getElementById('listPeople');
buttonDelete.style.display = 'none';
} ;
const makePlayer = (id) => {
console.log(`li ${id} was clicked!`)
let person = arrOfPeople.find(player => player.id == id)
let index = arrOfPeople.indexOf(person)
arrOfPeople.splice(index,1)
const newPlayer = new Player(person.id, person.name, true, true, true, true, person.yearsExperience)
listOfPlayers.push(newPlayer)
const listElement = document.getElementById('players')
const li = document.createElement("li")
const blueButton = document.createElement("button")
blueButton.innerHTML = "Blue team"
blueButton.style = "background: blue; color: white;"
blueButton.addEventListener('click', () => {
makeBlueTeam(person.id)
listElement.removeChild(li)
});
const redButton = document.createElement("button")
redButton.innerHTML = "Red team"
redButton.style = "background: red; color: white;"
redButton.addEventListener('click', () => {
makeRedTeam(person.id)
listElement.removeChild(li)
});
li.appendChild(blueButton)
li.appendChild(redButton)
listElement.append(li)
li.appendChild(document.createTextNode(`${person.name} - Years Experience: ${person.yearsExperience}`))
};
const makeBlueTeam = (id) => {
let person = listOfPlayers.find(player => player.id == id)
let index = listOfPlayers.indexOf(person)
listOfPlayers.splice(index, 1)
const newBlueTeammate = new BlueTeammate(person.id, person.name, 'Blue', 'Average Joe')
blueTeam.push(newBlueTeammate)
let bluePerson = blueTeam.find(player => player.id == id)
const listElement = document.getElementById('blue')
const li = document.createElement("li")
li.appendChild(document.createTextNode(`${bluePerson.name} is an ${bluePerson.mascot}`))
listElement.append(li)
};
const makeRedTeam = (id) => {
let person = listOfPlayers.find(player => player.id == id)
console.log(person)
let index = listOfPlayers.indexOf(person)
listOfPlayers.splice(index, 1)
const newRedTeammate = new RedTeammate(person.id, person.name, 'Red', 'Globo Gym')
redTeam.push(newRedTeammate)
let redPerson = redTeam.find(player => player.id == id)
const listElement = document.getElementById('red')
const li = document.createElement("li")
li.appendChild(document.createTextNode(`${redPerson.name} is on team ${redPerson.mascot}`))
listElement.append(li)
};