forked from SEI-SEA-1-25/object-array-drills
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercises.js
256 lines (217 loc) · 8.16 KB
/
exercises.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
console.log("main.js linked!");
////////////////////////////////////////////////
// Part 1: Linking
////////////////////////////////////////////////
// Link this JavaScript file to an HTML document.
// You'll know the file is correctly linked if the console says
// "main.js linked!"
////////////////////////////////////////////////
// Part 2: Working With Data Structures
////////////////////////////////////////////////
const album1 = {
title: "Talking Heads",
albumDetails: {
released: new Date("September 16, 1977"),
label: "Sire",
formats: ["LP"]
}
};
// 1. Retrieve the string "Sire" from album1, and save it in a sensibly named
// variable.
// 2. Change the title of album1 from "Talking Heads" to "Talking Heads: 77"
const album2 = {
title: "More Songs About Buildings and Food",
albumDetails: {
released: new Date("July 14, 1978"),
label: "Sire",
formats: ["LP", "8-track"]
}
};
const album3 = {
title: "Fear of Music",
albumDetails: {
released: "August 3, 1979",
label: "Sire",
formats: ["Cassette"]
}
};
// 3. Access album2's formats array and use an array method to add "LP" to
// album3's formats
// Check out the Array.push method!
// 4. Change the release date of album3 from a string into a Date object
// Look ahead to album4 for a clue!
const album4 = {
title: "Remain in Light",
albumDetails: {
released: new Date("October 8, 1980"),
formats: ["Cassette", "LP"]
}
};
// 5. Add the label "Sire" to album4's details
const album5 = {
title: "Speaking in Tongues",
albumDetails: {
released: new Date("May 31, 1983"),
label: "Sire"
}
};
// 6. Add a 'formats' array to album 5 and add "CD", "Cassette", and "LP"
const album6 = {
title: "Little Creatures",
albumDetails: {
released: new Date("June 10, 1985"),
labels: ["Sire", "emi"],
formats: ["CD", "cassette", "LP"]
}
};
// 7. Make the label "emi" in album6 all uppercase
// google how to make a string uppercase in js!
const album7 = {
title: "True Stories",
albumDetails: {
released: new Date("October 7, 1986"),
labels: "Sire, EMI",
formats: ["CD", "cassette", "LP"]
}
};
// 8. Convert album7's 'labels' property from the string value
// "Sire, EMI" into the array: ["Sire", "EMI"]
// google js array split!
const album8 = {
title: "Naked",
albumDetails: {
released: new Date("March 15, 1988"),
label: ["Sire", "EMI"],
formats: ["CD", "cassette", "LP"]
}
};
const talkingHeadsAlbums = [
album1,
album2,
album3,
album4,
album5,
album6,
album7,
album8
];
/////////////////////////////////////////////////////
// Part 3: More Tasks About Datatypes and Structures
/////////////////////////////////////////////////////
// 1. Create an object literal called `band`.
// 2. Give it the property `name` and set it to "Talking Heads"
// 3. Give it the property `members` and set it to an array with a single
// string, "David Byrne", in it.
// 4. Give it the property `albums` and set it to the array stored in the
// variable talkingHeadsAlbums
// 5. Add "Tiny Weymouth", "Chris Franz" and "Jerry Harrison" to the members
// array.
////////////////////////////////////////////////
// Part 4: Conditional Logic
////////////////////////////////////////////////
// 1. Write a conditional to console.log "Talking Heads were a prolific band"
// if the Talking Heads have 6 albums or more. Otherwise, console.log
// "Talking heads didn't have much output." Use the array of albums
// talkingHeadsAlbums above.
// 2. Write a conditional to check if the number of albums in
// talkingHeadsAlbums is odd or even, and then console.log
// "The number X is odd" or "The number X is even" with X being
// the number of albums.
// 3. Write conditionals to check if the number of albums in
// talkingHeadsAlbums is divisible by either 2 or 3, and then
// console.log one of:
// - "The number Y is divisible by 2",
// - "The number Y is divisible by 3",
// - "The number Y is divisible by 2 and 3", or
// - "The number Y is not divisible by 2 or 3",
//
// with Y being the number of albums.
// 4. Check your logic above against the numbers: 0, 1, 2, 6, 7, and 9.
// Make sure it always works!
/////////////////////////////////////////////////////
// Part 5: For Loops
/////////////////////////////////////////////////////
// 1. Use a for loop to print out the name of each Talking Heads album
// 2. Create a variable called `sireTally`, and set it to the integer value 0.
// Then use a for-loop to go through all the Talking Heads albums,
// incrementing sireTally if the album was released under the "Sire" label.
//
// Warning: some albums have a property `.label`, which is a string, and some
// have `.labels`, which is an Array!
/////////////////////////////////////////////////////
// Part 7: More Tasks With Conditionals and Iteration
/////////////////////////////////////////////////////
// 1. There is a Talking Heads concert at DAR Constitutional Hall, and
// the attending dignitaries will be sitting in three sections:
// "left", "center", and "right".
//
// The event is "open seating" (guests can choose any seat they want),
// however they must have a *premium ticket* to sit in first 3 rows of
// their section. *Standard ticket*-holders must sit behind row 3.
// Using the hardcoded list of dignitaries below, print out
// appropriate seating instructions.
//
// Example:
// const ticket1 = {
// name: "Madeline Albright",
// section: "right",
// type: "premium",
// seats: 1
// };
// const ticket1 = {
// name: "Newt Gingrich",
// section: "center",
// type: "standard",
// seats: 4
// };
//
// Messages:
// "Welcome, Madeline Albright! You may sit anywhere in the first 3 rows of the right section."
// "Welcome, Newt Gingrich! You and your party may sit anywhere except first 3 rows of the center section.
// Please be sure to leave no seats between you."
const tickets = [
{name: "Boutros Boutros-Ghali", section: "center", type: "premium", seats: 1},
{name: "Ann Richards", section: "left", type: "premium", seats: 2},
{name: "George Will", section: "left", type: "standard", seats: 2},
{name: "Marion Barry", section: "center", type: "standard", seats: 8},
{name: "Warren Christopher", section: "right", type: "standard", seats: 1},
{name: "Bob Dole", section: "center", type: "premium", seats: 3}
];
// 2. There is a concert at the LA County Fairgrounds by the Southland's
// hottest Talking Heads tribute band for zombie afficianados,
// "The Wailing Deads" (known as "The Walking Deads" until they received
// a cease-and-desist). Ticket prices are $50, $65, or $90 for
// standard, premier, and premier plus seating. Premier plus tickets
// receive free drinks.
//
// Discounted patrons (seniors, veterans, and students) receive a free
// $10 drinks voucher, while regular patrons receive none. Premier
// plus seats only cost $80 for discounted patrons.
//
// Everyone who dresses as a zombie in a giant business suit will
// receive a $10 drinks voucher.
//
// Based on a ticket request in the form of an object, print out
// a message for the given ticket.
//
// Treat missing data as an automatic false.
//
// Examples:
// - {amount: 50.00, discount: true, zombie: false} => "STANDARD $10 DRINKS"
// - {amount: 65.00, discount: false, zombie: false} => "PREMIER NO DRINKS"
// - {amount: 80.00, discount: false} => "ERROR: INVALID TICKET"
// - {amount: 80.00, discount: true} => "PREMIER PLUS"
// - {amount: 90.00} => "PREMIER PLUS"
// - {amount: 50.00, discount: true, zombie: true} => "STANDARD $20 DRINKS"
const tickets = [
{amount: 50.00, discount: false, zombie: true},
{amount: 60.00, discount: true, zombie: false},
{amount: 50.00},
{amount: 65.00, discount: true, zombie: true},
{amount: 90.00, discount: false},
{amount: 50.00, discount: true, zombie: false},
{amount: 50.00, zombie: true},
{amount: 80.00, discount: true},
{amount: 90.00},
{amount: 50.00, discount: true}
];