-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
649 lines (512 loc) · 28 KB
/
main.js
File metadata and controls
649 lines (512 loc) · 28 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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
"use strict"
let calc_btn = document.getElementById("action");
calc_btn.addEventListener("click", analyze);
/* I am getting the id's of these elements from my index.html so they can be called through my
main.js */
function analyze() {
let userSport = document.getElementById("userSport");
let userPreference = document.getElementById("userPreference");
let userPeriod = document.getElementById("userPeriod");
let userColor = document.getElementById("userColor");
/* Basketball Section- Red Basketball College teams past & present logic
For the basketball section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Basketball team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams outputs will have a social media "#" to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "College")
if (userPeriod.value == "Classic")
if (userColor.value == "Red") {
output("You are a Classic Northeastern University Basketball Fan 🏀🔴");
}
}
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "College")
if (userPeriod.value == "Current")
if (userColor.value == "Red") {
output("You are a Northeastern University Basketball Fan 🏀🔴 #GoHuskies");
}
}
/* Basketball Section- Red Professional teams past & present logic
For the basketball section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Basketball team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Classic")
if (userColor.value == "Red") {
output("You are a Classic Miam Heat Fan 🏀🔴");
}
}
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Current")
if (userColor.value == "Red") {
output("You are a Miami Heat Fan 🏀🔴 #feeltheburn");
}
}
/* Basketball Section- Blue College teams past & present logic
For the basketball section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Basketball team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "College")
if (userPeriod.value == "Current")
if (userColor.value == "Blue") {
output("You are a Duke University Fan 🏀🔵 #Duke'sbluedevils");
}
}
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "College")
if (userPeriod.value == "Classic")
if (userColor.value == "Blue") {
output("You are a Classic Duke University Fan 🏀🔵");
}
}
/* Basketball Section- Blue Professional teams past & present logic
For the basketball section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Basketball team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Classic")
if (userColor.value == "Blue") {
output("You are a Classic Dallas Maverick Fan 🏀🔵");
}
}
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Current")
if (userColor.value == "Blue") {
output("You are a Dallas Maverick Fan 🏀🔵 #MarvelousMavericks");
}
}
/* Basketball Section- Yellow Professional teams past & present logic
For the basketball section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Basketball team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Current")
if (userColor.value == "Yellow") {
output("You are a Golden State Warriors Fan 🏀🟡 #DubNation");
}
}
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Classic")
if (userColor.value == "Yellow") {
output("You are a Classic Golden State Warriors Fan 🏀🟡");
}
}
/* Basketball Section- Yellow College teams past & present logic
For the basketball section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Basketball team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "College")
if (userPeriod.value == "Current")
if (userColor.value == "Yellow") {
output("You are a Drexel University Fan 🏀🟡 #LetsGoDragons");
}
}
console.log("")
if (userSport.value == "Basketball") {
if (userPreference.value == "College")
if (userPeriod.value == "Classic")
if (userColor.value == "Yellow") {
output("You are a Classic Drexel University Fan 🏀🟡");
}
}
/* Soccer section */
/* Soccer Section- Blue Pro teams past & present logic
For the Soccer section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Soccer team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Current")
if (userColor.value == "Blue") {
output("You are a Chelsea Fan ⚽🔵 #COYB");
}
}
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Classic")
if (userColor.value == "Blue") {
output("You are a Classic Chelsea Fan ⚽🔵");
}
}
/* Soccer Section- Blue College teams past & present logic
For the Soccer section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Soccer team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "College")
if (userPeriod.value == "Current")
if (userColor.value == "Blue") {
output("You are a Georgetown Fan ⚽🔵 #GeorgetownHoyas");
}
}
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "College")
if (userPeriod.value == "Classic")
if (userColor.value == "Blue") {
output("You are a Classic Georgetown Fan ⚽🔵");
}
}
/* Soccer Section- Red Pro teams past & present logic
For the Soccer section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Soccer team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Current")
if (userColor.value == "Red") {
output("You are a Manchester United Fan ⚽🔴 #GloryGloryManUnited");
}
}
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Classic")
if (userColor.value == "Red") {
output("You are a Classic Manchester United Fan ⚽🔴");
}
}
/* Soccer Section- Red College teams past & present logic
For the Soccer section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Soccer team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "College")
if (userPeriod.value == "Current")
if (userColor.value == "Red") {
output("You are a Santa Clara University Fan ⚽🔴 #BuckyBroncos");
}
}
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "College")
if (userPeriod.value == "Classic")
if (userColor.value == "Red") {
output("You are a Classic Santa Clara University Fan ⚽🔴");
}
}
/* Soccer Section- Yellow College teams past & present logic
For the Soccer section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Soccer team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "College")
if (userPeriod.value == "Classic")
if (userColor.value == "Yellow") {
output("You are a Classic University of Wisconsin-Superior Fan ⚽🟡");
}
}
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "College")
if (userPeriod.value == "Current")
if (userColor.value == "Yellow") {
output("You are a University of Wisconsin-Superior Fan ⚽🟡 #BuzztheBeeGonnaStingYa");
}
}
/* Soccer Section- Yellow Pro teams past & present logic
For the Soccer section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Soccer team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Classic")
if (userColor.value == "Yellow") {
output("You are a Classic Norwich City F.C Fan ⚽🟡");
}
}
console.log("")
if (userSport.value == "Soccer") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Current")
if (userColor.value == "Yellow") {
output("You are a Norwich City F.C Fan #ProtectTheNest ⚽🟡");
}
}
/* Ice Hockey section */
/* Hockey Section- Blue College teams past & present logic
For the Hockey section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Hockey team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "College")
if (userPeriod.value == "Classic")
if (userColor.value == "Blue") {
output("You are a Classic Penn State Fan 🏒🔵");
}
}
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "College")
if (userPeriod.value == "Current")
if (userColor.value == "Blue") {
output("You are a Penn State Fan 🏒🔵 #LetsGoPanthers!");
}
}
/* Hockey Section- Blue Pro teams past & present logic
For the Hockey section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Hockey team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Current")
if (userColor.value == "Blue") {
output("You are a Toronto Maple Leafs Fan 🏒🔵 #WeMayBesweetButWeKeepOurPucksSticky!");
}
}
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Classic")
if (userColor.value == "Blue") {
output("You are a Classic Toronto Maple Leafs Fan 🏒🔵");
}
}
/* Hockey Section- Yellow College teams past & present logic
For the Hockey section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Hockey team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "College")
if (userPeriod.value == "Current")
if (userColor.value == "Yellow") {
output("You are a University of Michigan Fan 🏒🟡 #LetsGoWolverines!");
}
}
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "College")
if (userPeriod.value == "Classic")
if (userColor.value == "Yellow") {
output("You are a Classic University of Michigan Fan 🏒🟡");
}
}
/* Hockey Section- Yellow Pro teams past & present logic
For the Hockey section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Hockey team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Classic")
if (userColor.value == "Yellow") {
output("You are a Classic Boston Bruins Fan 🏒🟡");
}
}
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Current")
if (userColor.value == "Yellow") {
output("You are a Boston Bruins Fan 🏒🟡 #LetsGoBruins");
}
}
/* Hockey Section- Red College teams past & present logic
For the Hockey section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Hockey team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "College")
if (userPeriod.value == "Current")
if (userColor.value == "Red") {
output("You are a Northeastern Fan 🏒🔴 #LetsGoHuskies");
}
}
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "College")
if (userPeriod.value == "Classic")
if (userColor.value == "Red") {
output("You are a Classic Northeastern Fan 🏒🔴");
}
}
/* Hockey Section- Red Proteams past & present logic
For the Hockey section the logic here is that once a user has chosen basketball as their sport's preference
the output would be a Hockey team that depends on if a user prefers college or professional teams, classic or current teams and finally the output
is also decided by what a user's favorite color is.
Current teams often have a social media "#" as to show we live in current times as opposed to the past
when supporting a sports team could only be experienced in-person. Social media allows people to support
teams from anywhere in the world */
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Current")
if (userColor.value == "Red") {
output("You are a Detroit Red Wings Fan 🏒🔴 #RedBullGivesYouWings");
}
}
console.log("")
if (userSport.value == "Ice Hockey") {
if (userPreference.value == "Professional")
if (userPeriod.value == "Classic")
if (userColor.value == "Red") {
output("You are a Classic Detroit Red Wings Fan 🏒🔴");
}
}
/* this function fetches the input elements from the ID's of our input. After that is done
I am telling the computer to make the value blank once a certain action is done. This will
occur once we run the function through an evenlistener */
function clearInputValues() {
let inputOne = document.getElementById("userSport");
inputOne.value = "";
let inputTwo = document.getElementById("userPreference");
inputTwo.value = "";
let inputThree = document.getElementById("userPeriod");
inputThree.value = "";
let inputFour = document.getElementById("userColor");
inputFour.value = "";
}
/* this function fetches the output element in the html file our variable name for it is "o"
the output will clear once we add an eventlistener to it */
function clearOutput() {
let o = document.getElementById("output");
if (o) {
/* this was hard until I did some extensive research but what I found was since the output element is in a div in the
index html file I had to make sure the ".innerHTML" was there so the output content can then be
recognized in the string. Before I had it as let o=""; but the output wasn't clearing till I
added the .innerHTML */
o.innerHTML = "";
console.clear();
console.log("Output and console log have been cleared.");
}
}
/* the final function fetches the functions that clear the inputs and outputs as parameters. We combine this two funcitons into one new function call
"clearInputAndOutput" */
function clearInputAndOutput() {
clearInputValues();
clearOutput();
}
/* now for the magic, we get the id (refresh) of the second button on our index.html file and run the function that hosts
both the clearInput and clearOutput so that when a user clicks on the refresh button out inputs and outputs are cleared
from the quiz. */
document.getElementById("refresh").addEventListener("click", clearInputAndOutput);
/* ERROR STATES LOGIC
making the refresh function made me realize what happens if a user chooses to not answer all 4 questions?
My current outputs didn't take that into consideration so I added so error states using boolean logic and OR statements for
when a user doesn't answer all the questions but still presses the "Find my Team!" button to get their answer */
/* users answers not one or more of the 4 questions */
console.log("")
if (userSport.value == "" || userPreference.value == "" || userPeriod.value == "" || userColor.value == "") {
{
output("⚠️ Hey, I need you to answer more questions to give you a worthwhile answer ⚠️");
}
}
endOutput();
// Do not modify code below this line!
}
/* ***** function output() *****
Appends the provided String to an HTML element called "output". String may be output as plain text or as HTML.
Requirements: An element with id="output" in the current Document Object (generally the index.html)
Parameters:
content String to be added to "output"
htmlFlag Boolean (default false):
if false, add content within a <p> tag
if true, treat content as HTML ready to output
Returns: Nothing
******************************** */
function output(content, htmlFlag) {
if (content == undefined) {
console.log("WARNING: You did not provide anything to output");
} else {
let o = document.getElementById("output");
if (!htmlFlag) {
let p = document.createElement("p");
let tn = document.createTextNode(content);
p.appendChild(tn);
o.appendChild(p);
} else {
o.innerHTML += content;
}
}
}
/* ***** function endOutput() *****
Appends a horizontal rule (<hr> element) to Document Object with id="output".
Requirements: An element with id="output" in the current Document Object (generally the index.html)
Parameters: None
Returns: Nothing
*********************************** */
function endOutput() {
let o = document.getElementById("output");
o.appendChild(document.createElement("hr"));
}