-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmain.js
More file actions
198 lines (64 loc) · 3.31 KB
/
main.js
File metadata and controls
198 lines (64 loc) · 3.31 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
=======================================================
** Week 2 - Project 1 **
Below are a number of problems for you to solve
using JS. The JS code can be written below each
problem and the results can be displayed into the
HTML page. In some cases, you may want to check
within the console for verification of the array.
console.log();
=======================================================
*/
// 0. Connect the main.js document to the HTML page.
/* Add to the bottom of the HTML page: <script src="main.js"></script>*/
document.getElementById("q0").innerHTML = "JS Page Connected Properly!";
document.getElementById("q0").classList.add("status-good");
// 1. Declare a variable whose value is an empty array.
// Use any method you choose to add at least 4 items to it.
// 2. Add an additional item to the beginning of your array.
// 3. Remove the second and third items in your array.
// 4. Add two new items after the second item.
// 5. Log to the console: 'The current length of the array is....' using the .length method
// Use the following Array for questions 6-9:
var things = ['mug', 'book', 'mouse', 'plant', 'sunglasses'];
// 6. Change 'mouse' to 'keyboard'
// 7. Combine all of the elements of the array into a string.
// (Hint: check out the 'join' method.)
// 8. Remove the first item.
// 9. Remove all items from the things array.
// Use the following array for question 10:
var people = ['Bill', 'Ted', 'Emily', 'Andrea', 'Doug'];
// 10. Arrange the items alphabetically. Store this Array as orderedPeople
// 11. Create an array of arrays with the following three arrays:
var array1 = ["Fido", "Spot", "Rex", "Sparky"]
var array2 = ["Bulldog", "Lab", "Dalmation", "Beagle"]
var array3 = ["White", "Black", "Spotted", "Tri-color"]
// Goal:
var array4 = [
["Fido", "Spot", "Rex", "Sparky"],
["Bulldog", "Lab", "Dalmation", "Beagle"],
["White", "Black", "Spotted", "Tri-color"]
]
// 12. Remove "Sparky" and "White" from the above array of arrays.
// ADVANCED TRACK
// Use the following campingItems array for question 13
var campingItems = ['tent', 'hiking boots', 'picnic table', 'corn on the cob', 'cooler'];
// 13. Declare an array called lastItem using .pop() on the campingItems array.
// 14. Add two new items to lastItem, one at the beginning and one at the end.
// 15. Add s'mores to the lastItem array.
// 16. Create a new Array called reversedItems.
// The items should be the same as lastItem, only in reverse order.
// 17. Using the Arrays below, create a single Array
// called numberPets whose value is [12, 5, 9, 27, 'fish', 'dog']
var firstArray = [12, 5, 9, 27];
var secondArray = ['fish', 'dog'];
// 18: Try to arrange the following items from smallest to largest:
var sortingNumbers = [2, 5, 98, 55, 77, 300];
// If it doesn't sort as expected, explain why.
/* SANDBOX TRACK
Solving all of these problems is a great step in the right direction,
but the next step is coming up with your own arrangements to solve
new problems. Practice creating your own problems to solve and their solutions -
you can even challenge your classmates!
Also, consider how you can add/remove CSS styles to create added presentation with the results.
*/