-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs-graveyard.js
583 lines (461 loc) · 18.2 KB
/
js-graveyard.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
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
// ALL JS NEW AND OLD, TO KEEP MAIN.JS "CLEAN" AND IN CASE I WANT TO REFERENCE SOMETHING I'VE TRIED
// var answer = {
// dieDown: {
// answerOne: "It is\ncertain",
// answerThree: "Without\na\ndoubt",
// answerFive: "You may\nrely on\nit",
// answerSix: "As I see\nit\nyes",
// answerSeven: "Most\nlikely",
// answerEight: "Outlook\ngood",
// answerNine: "Yes",
// answerTen: "Signs\npoint to\nyes",
// answerEleven: "Reply hazy,\ntry\nagain",
// answerTwelve: "Ask again\nlater",
// answerThirteen: "Better\nnot tell\nyou\nnow",
// answerFourteen: "Cannot\npredict\nnow",
// answerFifteen: "Concentrate\nand ask\nagain",
// answerSixteen: "Don't\ncount\non\nit",
// answerSeventeen: "My\nreply\nis\nno",
// answerEighteen: "My\nsources\nsay\nno",
// answerNineteen: "Outlook\nnot so\ngood"
// },
// dieUp: {
// answerTwo: "It is\ndecidely\nso",
// answerFour: "Yes\ndefinitely",
// answerTwenty: "Very\ndoubtful"
// }
// }
// Need evenListener on submit button
// Set answer to be random, math.random?
// if dieDown, display none for dieUp div?
// document.getElementById("submitQuestion-btn").addEventListener("click", function() {document.getElementById("answer").innerHTML = "It is\ncertain"});
function removeAnswer() {
document.getElementsByClassName("eight-ball-img").style.display = "none";
// document.getElementById("get-your-answer").style.display = "none";
// document.getElementById("answer").style.display = "none";
console.log("removeAnswer is firing");
}
// I need a function that listens to a click on the "submit" button, which shows the random answer. Random answer includes gradient background, die, and answer.
// submitQuestionClick removes targeted id
// function submitQuestionClick() {
// var dieUpAnswer = document.getElementById("answer-background");
// if (dieUpAnswer.style.display === "none") {
// dieUpAnswer.style.display = "block";
// } else {
// dieUpAnswer.style.display = "none";
// }
// console.log("submitQuestion function is firing");
// }
// Playground
// document.getElementById("submitQuestion").addEventListener("click", function() {
// document.getElementById("answer").innerHTML = "It is\ncertain";
// console.log("checking to see if playground is firing");
// });
// clickSubmitQuestion is first successful function 11-22-19
// Add clickSubmitQuestion to onclick for button
// Original below
// function clickSubmitQuestion() {
// var addAnswer = document.getElementById("answer").innerHTML = "It is\ncertain";
// console.log("clickSubmitQuestion is firing");
// }
function addEntireAnswer() {
// creates <div id="answer-background"></div>
var answerBackground = document.createElement("div");
answerBackground.id = "answer-background";
// hoping to add answerBackground after ask-a-question (elementAbove)
// insertAdjacentHTML does not work
var elementAbove = document.querySelector(".ask-a-question");
elementAbove.insertAdjacentHTML("afterend", answerBackground);
console.log("addEntireAnswer is firing");
}
// v1 - Uncaught TypeError: Cannot set property "innerHTML" of null
function versionOneclickSubmitQuestionv1() {
// Creates div for gradient background
var addBackground = document.createElement("div");
addBackground.setAttribute("id", "answer-background");
console.log("addBackground");
// Creates div for die
var addDie = document.createElement("div");
addDie.setAttribute("id", "get-your-answer");
console.log("addDie");
// Adds die div into gradient background div
var dieWithBackground = addBackground.appendChild(addDie);
console.log("Appends addDie to addBackground");
// Creates p for answer
var placeAnswer = document.createElement("p");
placeAnswer.setAttribute("id", "answer");
console.log("placeAnswer");
// Adds answer to die
var addAnswer = document.getElementById("answer").innerHTML = "It is\ncertain";
console.log("addAnswer");
// Adds p for answer into div for die on background
var dieAnswer = addDie.appendChild(addAnswer);
console.log("Appends addAnswer to addDie");
// Adds answer to die with background
dieWithBackground.appendChild(dieAnswer);
// Adds die with answer and background to magic eight ball page
var askQuestionSection = document.getElementById("ask-question-section");
askQuestionSection.parentNode.insertBefore(dieWithBackground, askQuestionSection.nextSibling);
console.log("clickSubmitQuestion is firing");
}
var answer = {
'1': 'It is\ncertain',
'2': 'Without\na\ndoubt',
'3': 'You may\nrely on\nit',
'4': 'As I see\nit\nyes',
'5': 'Most\nlikely',
'6': 'Outlook\ngood',
'7': 'Yes',
'8': 'Signs\npoint to\nyes',
'9': 'Reply hazy,\ntry\nagain',
'10': 'Ask again\nlater',
'11': 'Better\nnot tell\nyou\nnow',
'12': 'Cannot\npredict\nnow',
'13': 'Concentrate\nand ask\nagain',
'14': 'Don\'t\ncount\non\nit',
'15': 'My\nreply\nis\nno',
'16': 'My\nsources\nsay\nno',
'17': 'Outlook\nnot so\ngood'
// '18': 'It is\ndecidely\nso',
// '19': 'Yes\ndefinitely',
// '20': 'Very\ndoubtful'
}
// randomAnswer takes answer and returns a random answer
var randomAnswer = answer[Object.keys(answer)[Math.floor(Math.random() * Object.keys(answer).length)]];
console.log(randomAnswer);
// v2
function clickSubmitQuestion() {
// Creates the p for the answer
var createAnswer = document.createElement("p");
createAnswer.setAttribute("id", "answer");
console.log("p for answer");
// Adds answer
var addAnswer = document.createTextNode(`${randomAnswer}`);
// var addAnswer = document.createTextNode("It is\ncertain");
console.log("adds answer");
// Appends answer to p with id answer
createAnswer.appendChild(addAnswer);
console.log("appends answer to p");
// Creates div for gradient background
var addBackground = document.createElement("div");
addBackground.setAttribute("id", "answer-background");
// Creates div for die
var addDie = document.createElement("div");
addDie.setAttribute("id", "get-your-answer");
addDie.setAttribute("class", "die-down");
console.log("addDie");
// Appends p for answer to die div
addDie.appendChild(createAnswer);
// Adds die div into gradient background div
addBackground.appendChild(addDie);
console.log("Appends addDie to addBackground");
// Adds die with answer and background to magic eight ball page
var askQuestionSection = document.getElementById("ask-question-section");
askQuestionSection.parentNode.insertBefore(addBackground, askQuestionSection.nextSibling);
console.log("addBackground");
}
// what was js-graveyard-v2
var answer = {
'1': 'It is<br>certain',
'2': 'Without<br>a<br>doubt',
'3': 'You may<br>rely on<br>it',
'4': 'As I see<br>it<br>yes',
'5': 'Most<br>likely',
'6': 'Outlook<br>good',
'7': 'Yes',
'8': 'Signs<br>point to<br>yes',
// '9': 'Reply hazy,<br>try<br>again',
'10': 'Ask again<br>later',
// '11': 'Better<br>not tell<br>you<br>now',
'12': 'Cannot<br>predict<br>now',
// '13': 'Concentrate<br>and ask<br>again',
'14': 'Don\'t<br>count<br>on<br>it',
'15': 'My<br>reply<br>is<br>no',
'16': 'My<br>sources<br>say<br>no',
'17': 'Outlook<br>not so<br>good',
'18': 'It is<br>decidely<br>so',
'19': 'Yes<br>definitely',
// '20': 'Very<br>doubtful'
}
var dieUp = [9, 11, 13, 20];
// v2
function clickSubmitQuestion() {
// randomAnswer takes answer and returns a random answer
var randomAnswer = answer[Object.keys(answer)[Math.floor(Math.random() * Object.keys(answer).length)]];
console.log(randomAnswer);
// Creates the p for the answer
var createAnswer = document.createElement("p");
createAnswer.setAttribute("id", "answer");
// can now use .innerHTML to "add answer" instead of the current var addAnswer below. This will allow <br>'s inside of the var answer output
createAnswer.innerHTML = `${randomAnswer}`;
console.log("p with random answer");
// Adds answer
// var addAnswer = document.createTextNode(`${randomAnswer}`);
// console.log("adds answer");
// Appends answer to p with id answer
// createAnswer.appendChild(addAnswer);
// console.log("appends answer to p");
// Creates div for gradient background
var addBackground = document.createElement("div");
addBackground.setAttribute("id", "answer-background");
// Creates div for die
var addDie = document.createElement("div");
addDie.setAttribute("id", "get-your-answer");
addDie.setAttribute("class", "die-down");
console.log("addDie");
// Appends p for answer to die div
addDie.appendChild(createAnswer);
// Adds die div into gradient background div
addBackground.appendChild(addDie);
console.log("Appends addDie to addBackground");
// Adds die with answer and background to magic eight ball page
var askQuestionSection = document.getElementById("ask-question-section");
askQuestionSection.parentNode.insertBefore(addBackground, askQuestionSection.nextSibling);
console.log("addBackground");
return false;
}
function removeAnswer() {
document.getElementsByClassName("eight-ball-img").style.display = "none";
// document.getElementById("get-your-answer").style.display = "none";
// document.getElementById("answer").style.display = "none";
console.log("removeAnswer is firing");
}
// what was js-graveyard-v3
// var answer = {
// '1': 'It is<br>certain',
// '2': 'Without<br>a<br>doubt',
// '3': 'You may<br>rely on<br>it',
// '4': 'As I see<br>it<br>yes',
// '5': 'Most<br>likely',
// '6': 'Outlook<br>good',
// '7': 'Yes',
// '8': 'Signs<br>point to<br>yes',
// '9': 'Reply<br>hazy,<br>try again', //dieUp
// '10': 'Ask again<br>later',
// '11': 'Better<br>not tell<br>you<br>now', //dieUp
// '12': 'Cannot<br>predict<br>now',
// '13': 'Concentrate<br>and ask<br>again',
// '14': 'Don\'t<br>count<br>on<br>it',
// '15': 'My<br>reply<br>is<br>no',
// '16': 'My<br>sources<br>say<br>no',
// '17': 'Outlook<br>not so<br>good',
// '18': 'It is<br>decidely<br>so',
// '19': 'Yes<br>definitely',
// '20': 'Very<br>doubtful' //dieUp
// }
var answer = [
{ 'answer': 'It is<br>certain' },
{ 'answer': 'Without<br>a<br>doubt' },
{ 'answer': 'You may<br>rely on<br>it' },
{ 'answer': 'As I see<br>it<br>yes' },
{ 'answer': 'Most<br>likely' },
{ 'answer': 'Outlook<br>good' },
{ 'answer': 'Yes' },
{ 'answer': 'Signs<br>point to<br>yes' },
{ 'answer': 'Reply<br>hazy,<br>try again', 'direction': 'dieUp' }, //dieUp
{ 'answer': 'Ask again<br>later' },
{ 'answer': 'Better<br>not tell<br>you<br>now', 'direction': 'dieUp' }, //dieUp
{ 'answer': 'Cannot<br>predict<br>now' },
{ 'answer': 'Concentrate<br>and ask<br>again' },
{ 'answer': 'Don\'t<br>count<br>on<br>it' },
{ 'answer': 'My<br>reply<br>is<br>no' },
{ 'answer': 'My<br>sources<br>say<br>no' },
{ 'answer': 'Outlook<br>not so<br>good' },
{ 'answer': 'It is<br>decidely<br>so' },
{ 'answer': 'Yes<br>definitely' },
{ 'answer': 'Very<br>doubtful', 'direction': 'dieUp' } //dieUp
]
// v2.2
function clickSubmitQuestion() {
// randomAnswer takes answer and returns a random answer
var randomAnswerID = Object.keys(answer)[Math.floor(Math.random() * Object.keys(answer).length)];
var randomAnswer = answer[randomAnswerID];
console.log(randomAnswer);
// Creates the p for the answer
var createAnswer = document.createElement("p");
createAnswer.setAttribute("id", "answer");
// can now use .innerHTML to "add answer" instead of the current var addAnswer below. This will allow <br>'s inside of the var answer output
createAnswer.innerHTML = `${randomAnswer}`;
console.log("p with random answer");
// Adds answer
// var addAnswer = document.createTextNode(`${randomAnswer}`);
// console.log("adds answer");
// Appends answer to p with id answer
// createAnswer.appendChild(addAnswer);
// console.log("appends answer to p");
// Creates div for gradient background
var addBackground = document.createElement("div");
addBackground.setAttribute("id", "answer-background");
// Creates div for die
var addDie = document.createElement("div");
addDie.setAttribute("id", "get-your-answer");
if (dieUp.indexOf(randomAnswerID) > -1) {
addDie.setAttribute("class", "die-up");
console.log("addDieUP");
} else {
addDie.setAttribute("class", "die-down");
console.log("addDieDown");
}
// Appends p for answer to die div
addDie.appendChild(createAnswer);
// Adds die div into gradient background div
addBackground.appendChild(addDie);
console.log("Appends addDie to addBackground");
// Adds die with answer and background to magic eight ball page
var answerWrapper = document.getElementById("answer-wrapper");
answerWrapper.innerHTML = addBackground.outerHTML;
console.log("addBackground");
return false;
}
function removeAnswer() {
document.getElementsByClassName("eight-ball-img").style.display = "none";
// document.getElementById("get-your-answer").style.display = "none";
// document.getElementById("answer").style.display = "none";
console.log("removeAnswer is firing");
}
// v3
// Function that validates question
// function validateQuestion() {
// var validYesNoQuestions = [
// 'am',
// 'are',
// 'aren\'t',
// 'can\'t',
// 'do',
// 'does',
// 'don\'t',
// 'is',
// 'should',
// 'isn\'t',
// 'will',
// 'have',
// 'could',
// 'had',
// 'did',
// 'were',
// 'was',
// 'would',
// 'can',
// 'has',
// 'shouldn\'t',
// 'wouldn\'t',
// 'couldn\'t',
// 'hadn\'t',
// 'didn\'t',
// 'doesn\'t',
// 'hasn\'t',
// 'haven\'t',
// 'weren\'t',
// 'may',
// 'ought',
// 'won\'t',
// ]
// searches inside of validYesNoQuestions
// var question =
// if else
// if (question.toLowerCase() == validYesNoQuestions.toLowerCase()) {
// clickSubmitQuestion();
// } else {
// alert('Please ask the Magic Eight Ball a valid Yes or No question');
// }
// return false;
// }
// Function that creates random answer
function clickSubmitQuestion() {
var answers = [
{ 'answer': 'It is<br>certain' },
{ 'answer': 'Without<br>a<br>doubt' },
{ 'answer': 'You may<br>rely on<br>it' },
{ 'answer': 'As I see<br>it<br>yes' },
{ 'answer': 'Most<br>likely' },
{ 'answer': 'Outlook<br>good' },
{ 'answer': 'Yes' },
{ 'answer': 'Signs<br>point to<br>yes' },
{ 'answer': 'Reply<br>hazy,<br>try again', 'direction': 'dieUp' }, //dieUp
{ 'answer': 'Ask again<br>later' },
{ 'answer': 'Better<br>not tell<br>you<br>now', 'direction': 'dieUp' }, //dieUp
{ 'answer': 'Cannot<br>predict<br>now' },
{ 'answer': 'Concentrate<br>and ask<br>again' },
{ 'answer': 'Don\'t<br>count<br>on<br>it' },
{ 'answer': 'My<br>reply<br>is<br>no' },
{ 'answer': 'My<br>sources<br>say<br>no' },
{ 'answer': 'Outlook<br>not so<br>good' },
{ 'answer': 'It is<br>decidely<br>so' },
{ 'answer': 'Yes<br>definitely', 'direction': 'dieUp' }, //dieUp
{ 'answer': 'Very<br>doubtful', 'direction': 'dieUp' } //dieUp
]
// randomAnswer takes answer and returns a random answer
var randomAnswerID = [Math.floor(Math.random() * answers.length)];
var randomAnswerObj = answers[randomAnswerID];
var randomAnswer = randomAnswerObj.answer;
console.log(randomAnswerObj);
// Creates the p for the answer
var createAnswer = document.createElement("p");
createAnswer.setAttribute("id", "answer");
createAnswer.innerHTML = `${randomAnswer}`;
console.log("p with random answer");
// Creates div for gradient background
var addBackground = document.createElement("div");
addBackground.setAttribute("id", "answer-background");
// Creates div for die
var addDie = document.createElement("div");
addDie.setAttribute("id", "get-your-answer");
// Determines orientation of die and answer
if (randomAnswerObj.direction != null && randomAnswerObj.direction == 'dieUp') {
addDie.setAttribute("class", "die-up");
console.log("addDieUP");
} else {
addDie.setAttribute("class", "die-down");
console.log("addDieDown");
}
// Appends p for answer to die div
addDie.appendChild(createAnswer);
// Adds die div into gradient background div
addBackground.appendChild(addDie);
console.log("Appends addDie to addBackground");
// Adds die with answer and background to magic eight ball page
var answerWrapper = document.getElementById("answer-wrapper");
answerWrapper.innerHTML = addBackground.outerHTML;
console.log("addBackground");
return false;
};
// I want the Submit Your Question button to convert to a Ask Another Question button
// I believe I need an event listener on the button to listen for a click
// I want the click to changed the id of submitQuestion to questionAsked that changes the functionality of the button to "reset" the answer and clears the question, using the resetAnswer function
// Function that resets answer
// function updateClass() {
// if (this.classList.contains('not-answered')) {
// this.classList.remove('not-answered');
// } else this.classList.add('answered');
// console.log('Adding or removing class answered is working from updateClass');
// };
// function resetAnswer() {
// document.getElementById('submitQuestion').addEventListener('click', updateClass);
// };
function clickResetButton() {
// removes answer from DOM when reset button is clicked
const parentElem = document.getElementById('answer-wrapper');
const childElem = document.getElementById('answer-background');
parentElem.removeChild(childElem);
// removes question from form input
document.getElementById('form-for-question').reset();
if (btnText.value == 'Ask Another Question') {
document.getElementById('submitQuestion').setAttribute('onclick', 'resetAnswer2();');
btnText.value = 'Submit Your Question';
btnText.innerHTML = 'Submit Your Question';
}
}
function resetAnswer2() {
// document.getElementById('submitQuestion').addEventListener('click', updateClass2);
var btnText = document.getElementById('submitQuestion');
if (btnText.value == 'Submit Your Question') {
btnText.value = 'Ask Another Question';
btnText.innerHTML = 'Ask Another Question';
document.getElementById('submitQuestion').setAttribute('onclick', 'clickResetButton();');
}
// else {
// document.getElementById('submitQuestion').setAttribute('onclick', 'resetAnswer2();');
// btnText.value = 'Submit Your Question';
// btnText.innerHTML = 'Submit Your Question';
// }
}