-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSWeek5CodingAssignment.js
More file actions
140 lines (121 loc) · 3.43 KB
/
JSWeek5CodingAssignment.js
File metadata and controls
140 lines (121 loc) · 3.43 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
class WorshipPractice {
constructor(player, instrument){
this.player = player;
this.instrument = instrument;
}
describe() {
return `${this.player} plays ${this.instrument}.`;
}
}
class WorshipTeam {
constructor(subteam) {
this.subteam = subteam;
this.subteams = [];
}
addName(WorshipPractice) {
if (WorshipPractice instanceof WorshipPractice) {
this.players.push(WorshipPractice);
} else {
throw new Error(`You can only add an instance of name. Argument is not a worship player; ${WorshipPractice}`);
}
}
describe() {
return `${this.names} has ${this.WorshipPractice.length} players.`;
}
}
class Menu {
constructor() {
this.subteams = [];
this.selectedSubTeam = null;
}
start() {
let selection = this.showMainMenuOptions();
while (selection != 0) {
switch (selection) {
case '1':
this.createSubTeam();
break;
case '2':
this.viewSubTeam();
break;
case '3':
this.deleteSubTeam();
break;
case '4':
this.displaySubTeam();
break;
default:
selection = 0;
}
selection = this.showMainMenuOptions();
}
alert('Farewell!');
}
showMainMenuOptions() {
return prompt(`
0) Exit
1) Create New Sub Team
2) View Sub Team
3) Delete Sub Team
4) Display All Sub Teams
`);
}
showSubTeamMenuOptions(subTeamInfo) {
return prompt (`
0) Back
1) Create Player
2) Delete Player
---------------------
${subTeamInfo}
`);
}
createSubTeam() {
let subteam = prompt('Enter name for new sub team: ');
this.subteams.push(new WorshipTeam(subteam));
}
viewSubTeam() {
let choice = prompt('Enter the choice of sub team you want to view: ');
if (choice>-1 && choice<this.subteams.length) {
this.selectedSubTeam = this.subteams[choice];
let subTeamName = 'Sub Team Name: ' + this.selectedSubTeam.subteam + '\n';
for (let i=0; i<this.selectedSubTeam.subteams.length; i++) {
subTeamName += i + ') ' + this.selectedSubTeam.subteams[i].player
+ ' - ' + this.selectedSubTeam.subteams[i].instrument + '\n';
}
let selection = this.showSubTeamMenuOptions(subTeamName);
switch (selection) {
case '1':
this.createPlayer();
break;
case '2':
this.deletePlayer();
}
}
}
deleteSubTeam() {
let choice = prompt('Enter the choice of sub team that you want to delete: ');
if (choice>-1 && choice<this.subteams.length) {
this.subteams.splice(choice, 1);
}
}
displaySubTeam() {
let subTeamString = '';
for (let i=0; i<this.subteams.length; i++) {
subTeamString += i + ') ' + this.subteams[i].subteam + '\n';
}
alert(subTeamString);
}
createPlayer() {
let player = prompt('Enter name for new player: ');
let instrument = prompt('Enter instrument for new player: ');
this.selectedSubTeam.subteams.push(new WorshipPractice(player, instrument));
}
deletePlayer() {
let choice = prompt('Enter your choice of player that you want to delete: ');
if(choice>-1 && choice<this.selectedSubTeam.subteams.length) {
this.selectedSubTeam.subteams.splice(choice, 1);
}
}
}
let menu = new Menu();
menu.start();