-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
315 lines (262 loc) · 11.5 KB
/
index.html
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<!-- this is my github URL
https://github.com/Hardish/javascript101.git
-->
<!DOCTYPE html>
<html>
<h3>Javascript Basics</h3>
<!-- <button onclick="cleanAndCountCharacters()">
clean and count words
</button> -->
<body>
</body>
</html>
<style>
#rootContainer {
display: flex;
}
.root-container {
position: relative;
}
.root-container .header {
position: relative;
}
.root-container .main {
position: relative;
}
.root-container .footer {
position: relative;
}
.startups-container {
background-color: gray;
}
.red {
background-image: red;
}
.blue {
background-image: blue;
}
.gold {
background-image: gold;
}
</style>
<script>
var colors = ['red', 'blue', 'gold'];
var chicagoStartups = [
' Interior Define ',
'Classkick',
'teaBOT .$',
'Pritzker Group Venture Capital',
'Teln!yx !!',
'ShipBob ~~$$$',
'Hologram',
'Tovala ',
' MANOR',
'ShuttleCloud 999987',
'gtrot @@@@@',
'DealsGoRound ****',
' Groovebug',
'Stage$$$Bloc',
'Shiftgig',
'ParkWhiz'
];
function clearDocument() {
var rootDiv = document.getElementById('rootContainer');
if (rootDiv) {
while (rootDiv.hasChildNodes()) {
rootDiv.removeChild(rootDiv.lastChild);
}
}
}
function initDocument() {
clearDocument();
var rootDiv = document.createElement('div');
rootDiv.id = 'rootContainer';
var companyNamesContainer = document.createElement('div');
chicagoStartups.forEach( function(chicagoStartup, index) {
var childDiv = document.createElement('div');
var text = document.createTextNode(index.toString().concat(' .) ').concat(chicagoStartup));
childDiv.appendChild(text);
companyNamesContainer.appendChild(childDiv);
});
rootDiv.appendChild(companyNamesContainer);
document.body.appendChild(rootDiv);
document.body.style.backgroundColor = "grey";
}
function initReverse() {
var reverseContainer = document.createElement('div');
reverseContainer.id = 'reverseContainer';
var reverseBtn = document.createElement('button');
var btnText = document.createTextNode('Reverse');
reverseBtn.onclick = renderReversedElements;
reverseBtn.appendChild(btnText);
var reverseButtonContainer = document.createElement('div');
reverseButtonContainer.appendChild(reverseBtn);
document.getElementById('rootContainer').appendChild(reverseButtonContainer);
document.getElementById('rootContainer').appendChild(reverseContainer);
}
function initCleanAndCount() {
var cleanandcountContainer = document.createElement('div');
cleanandcountContainer.id = 'cleanandcountContainer';
var cleanandcountBtn = document.createElement('button');
var btnText = document.createTextNode('clean and count words');
cleanandcountBtn.onclick = cleanAndCountCharacters;
cleanandcountBtn.appendChild(btnText);
var cleanandcountButtonContainer = document.createElement('div');
cleanandcountButtonContainer.appendChild(cleanandcountBtn);
document.getElementById('rootContainer').appendChild(cleanandcountButtonContainer);
document.getElementById('rootContainer').appendChild(cleanandcountContainer);
}
function initToggle() {
var toggleContainer = document.createElement('div');
toggleContainer.id = 'toggleContainer';
var toggleBtn = document.createElement('button');
var btnText = document.createTextNode('Toggle Display');
toggleBtn.onclick = toggleDisplay;
toggleBtn.appendChild(btnText);
var toggleButtonContainer = document.createElement('div');
toggleButtonContainer.appendChild(toggleBtn);
document.getElementById('rootContainer').appendChild(toggleButtonContainer);
document.getElementById('rootContainer').appendChild(toggleContainer);
}
function renderReversedElements() {
var reverseContainer = document.getElementById('reverseContainer');
var reversedChicagoStartups = [];
if (reverseContainer) {
if (reverseContainer.hasChildNodes()) {
while (reverseContainer.hasChildNodes()) {
reversedChicagoStartups.push(reverseContainer.lastChild.innerHTML);
reverseContainer.removeChild(reverseContainer.lastChild);
}
reversedChicagoStartups.forEach(function(startup, index) {
// console.log(startup);
var childDiv = document.createElement('div');
var text = document.createTextNode(startup);
childDiv.appendChild(text);
reverseContainer.appendChild(childDiv);
});
}
else {
chicagoStartupsReverse().forEach(function(startup) {
var childDiv = document.createElement('div');
var text = document.createTextNode(startup);
childDiv.appendChild(text);
reverseContainer.appendChild(childDiv);
reverseContainer.style.backgroundColor = "red";
});
}
}
}
function chicagoStartupsReverse() {
var reversedStartups = [];
for(var i = chicagoStartups.length-1; i >= 0; i--)
{
reversedStartups.push(i.toString().concat(' .) ').concat(chicagoStartups[i]));
}
return reversedStartups;
}
function cleanAndCountCharacters() {
var cleanandcountContainer = document.getElementById('cleanandcountContainer');
if (cleanandcountContainer) {
if (!cleanandcountContainer.hasChildNodes()) {
cleanandcountDisplay().forEach(function(startup, index) {
var childDiv = document.createElement('div');
var text = document.createTextNode(startup);
childDiv.appendChild(text);
cleanandcountContainer.appendChild(childDiv);
cleanandcountContainer.style.backgroundColor = "gold";
});
}
}
}
function cleanandcountDisplay() {
console.log('CLEAN AND COUNT CHARACTERS');
var cleanedandcountStartups = [];
// var countStartups = [];
for (var i=0;i<chicagoStartups.length;i++){
var temp = chicagoStartups[i].replace(/\s\s+/g, ' ');
var temp2 = JSON.stringify(getOccurencies(chicagoStartups[i].toLowerCase()));
cleanedandcountStartups.push(i.toString().concat(' .) ').concat(temp.replace(/[^a-zA-Z 0-9]+/g,'').trim() + " - " + temp.replace(/[^a-zA-Z 0-9]+/g,'').trim().length + " - " + temp2));
}
return cleanedandcountStartups;
}
function getOccurencies(b){
var occur = {};
b.split('').forEach(function(n){
occur[n] = b.split('').filter(function(i){ return i == n; }).length;
});
return occur;
}
function toggleDisplay() {
var toggleContainer = document.getElementById('toggleContainer');
var toggledDivSpanChicagoStartups = [];
if (toggleContainer) {
if (toggleContainer.hasChildNodes()) {
while (toggleContainer.hasChildNodes()) {
toggledDivSpanChicagoStartups.push(toggleContainer.firstChild.innerHTML);
toggleContainer.removeChild(toggleContainer.firstChild);
}
toggledDivSpanChicagoStartups.forEach(function(startup, index) {
var childDiv = document.createElement('div');
var text = document.createTextNode(startup);
childDiv.appendChild(text);
toggleContainer.appendChild(childDiv);
});
}
else {
toggleDivSpanDisplay().forEach(function(startup, index) {
var childDiv = document.createElement('span');
var text = document.createTextNode(startup);
childDiv.appendChild(text);
toggleContainer.appendChild(childDiv);
toggleContainer.style.backgroundColor = "blue";
});
}
}
}
function toggleDivSpanDisplay() {
var toggleStartups = [];
for(var i = 0; i < chicagoStartups.length; i++)
{
toggleStartups.push(" " + i.toString().concat(' .) ').concat(chicagoStartups[i]));
}
return toggleStartups;
}
function run() {
initDocument();
initReverse();
initToggle();
initCleanAndCount();
}
run();
var flags = {
displayInstructions: true
};
//TODO INVOKE THIS ANONYMOUS FUNCTION TO DISPLAY HOMEWORK INSTRUCTIONS IN THE CONSOLE
(function() {
if (flags.displayInstructions) {
console.log(`
ASSUMPTIONS: !!! NO JQUERY !!!
TODO INDICATES THAT A SOLUTION IS REQUIRED
PLEASE INCLUDE YOUR GITHUB URL AS A COMMENT
EX. // https://github.com/Chandler-Gegg/javascript101.git
Feel free to complete the exercises in whatever order you like.
Make sure to push your code to your own github repo as well as SUBMIT A ZIPFILE TO D2L.
HOMEWORK IS DUE WEDNESDAYS AT MIDNIGHT NO EXCEPTIONS.
dont forget to slack me the url to your github account as well.
You can earn extra credit by using the provided css classes in the style tag or additionally
you can pull in an external css library like bootstrap. if you bring in bootstrap make sure to style
the buttons using bootstraps built in button styling classes.
Additionally, can earn extra credit by using an object to count the number of occurrences
of each character accross all startup names and style and display the results as part of the
"cleanAndCountCharacters" function.
If you are having trouble getting started, I would spend a lot of time reviewing the source code provided in the reverse example.
Make sure I understand whats going on and do a google search on anything that is confusing.
THE BETTER YOU UNDERSTAND THE EXAMPLE THE EASIER THIS SHOULD BE. THEN REVIEW THE TODOS AND START BY TRYING TO SOLVE THE EASIEST
PROBLEM.
FROM MY OWN EXPERIENCE, I FIND THAT WHEN IM STRUGGLING WITH A PROBLEM, IT USUALLY MEANS
I DONT FULLY UNDERSTAND THE TOOLS THAT I AM USING.
GOOD LUCK, SEE YOU ON THE FLIPPITY FLOP "\_(**/)_/"
`);
}
})();
</script>