forked from ChromeGaming/GameSphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
1951 lines (1696 loc) · 55.3 KB
/
script.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
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Global
// These variables set to true when player solves puzzle:
// Please comment here with ✅ as triggers are added to puzzles:
var puzzlerSolved = false; // ✅
var mathPuzzleSolved = false; // ✅
var flexboxPuzzleSolved = false; // ✅
var mirrorPuzzleSolved = false; // ✅
var pipePuzzleSolved = false; // ✅
var recursionPuzzleSolved = false; // ✅
// Theme color variables - please use in all color functions.
var white = "#e6e6e6";
var darkestBlueColor = "#071e26";
var greyishBlueColor = "#06394c";
var brightBlueColor = "#0c4383";
var turquoiseBlueColor = "#22a0b6";
var palestBlueColor = "#6a96b9";
var darkMagentaColor = "#7b1346";
var magentaColor = "#cb0c59";
var pinkColor = "#eb649f";
// End Global
// Room scene
// Changes fill color of elements <selectors> to <color>
function toColor(selectors, color) {
var item = document.querySelectorAll(selectors);
item.forEach(function(i) {
i.style.fill = color;
});
}
// Changes opacity of element <selector> to <opacity>
function toOpacity(selector, opacity) {
var item = document.querySelector(selector);
item.style.opacity = opacity;
}
function abacusToColor() {
toColor("#abacus .st0", magentaColor);
}
function abacusToWhite() {
toColor("#abacus .st0", white);
}
function boxToColor() {
toColor("#box .st0", pinkColor);
}
function boxToWhite() {
toColor("#box .st0", white);
}
function mirrorToColor() {
toColor("#mirror .st0", palestBlueColor);
}
function mirrorToWhite() {
toColor("#mirror .st0", white);
}
function mirrorToColor() {
toColor("#mirror .st0", palestBlueColor);
}
function mirrorToWhite() {
toColor("#mirror .st0", white);
}
function radiatorToColor() {
toColor("#radiator .st0", darkMagentaColor);
}
function radiatorToWhite() {
toColor("#radiator .st0", white);
}
function computerToColor() {
toColor("#computer #desktop .st0", brightBlueColor);
}
function computerToWhite() {
toColor("#computer .st0", white);
}
function posterToTransparent() {
toOpacity("#poster", "0.2");
}
function posterToOpaque() {
toOpacity("#poster", "1");
}
function tilesToColor() {
toColor("#tiles .st0", turquoiseBlueColor);
}
function tilesToWhite() {
toColor("#tiles .st0", white);
}
document
.getElementById("mathPuzzleBtn")
.addEventListener("mouseover", abacusToColor);
document
.getElementById("mathPuzzleBtn")
.addEventListener("mouseout", abacusToWhite);
document
.getElementById("flexboxPuzzleBtn")
.addEventListener("mouseover", boxToColor);
document
.getElementById("flexboxPuzzleBtn")
.addEventListener("mouseout", boxToWhite);
document
.getElementById("mirrorPuzzleBtn")
.addEventListener("mouseover", mirrorToColor);
document
.getElementById("mirrorPuzzleBtn")
.addEventListener("mouseout", mirrorToWhite);
document
.getElementById("pipePuzzleBtn")
.addEventListener("mouseover", radiatorToColor);
document
.getElementById("pipePuzzleBtn")
.addEventListener("mouseout", radiatorToWhite);
document
.getElementById("recursionPuzzleBtn")
.addEventListener("mouseover", computerToColor);
document
.getElementById("recursionPuzzleBtn")
.addEventListener("mouseout", computerToWhite);
document
.getElementById("puzzlerBtn")
.addEventListener("mouseover", posterToTransparent);
document
.getElementById("puzzlerBtn")
.addEventListener("mouseout", posterToOpaque);
document
.getElementById("puzzlerBtn")
.addEventListener("mouseover", tilesToColor);
document
.getElementById("puzzlerBtn")
.addEventListener("mouseout", tilesToWhite);
// End room scene
// Cheryl Velez - Puzzler
// MODAL
// Get the modal
var puzzlerModal = document.getElementById("puzzlerModal");
// Get the button that opens the modal
var puzzlerBtn = document.getElementById("puzzlerBtn");
// Get the <span> element that closes the modal
var closePuzzler = document.getElementsByClassName("close-puzzler")[0];
// When the user clicks the button, open the modal
puzzlerBtn.onclick = function() {
puzzlerModal.style.display = "grid";
};
// When the user clicks on <span> (x), close the modal and check whether all puzzles solved
closePuzzler.onclick = function() {
puzzlerModal.style.display = "none";
verify();
};
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == puzzlerModal) {
puzzlerModal.style.display = "none";
}
};
// END MODAL
// Start JS for Puzzler Puzzler
!(function(a) {
function f(a, b) {
if (!(a.originalEvent.touches.length > 1)) {
a.preventDefault();
var c = a.originalEvent.changedTouches[0],
d = document.createEvent("MouseEvents");
d.initMouseEvent(
b,
!0,
!0,
window,
1,
c.screenX,
c.screenY,
c.clientX,
c.clientY,
!1,
!1,
!1,
!1,
0,
null
),
a.target.dispatchEvent(d);
}
}
if (((a.support.touch = "ontouchend" in document), a.support.touch)) {
var e,
b = a.ui.mouse.prototype,
c = b._mouseInit,
d = b._mouseDestroy;
(b._touchStart = function(a) {
var b = this;
!e &&
b._mouseCapture(a.originalEvent.changedTouches[0]) &&
((e = !0),
(b._touchMoved = !1),
f(a, "mouseover"),
f(a, "mousemove"),
f(a, "mousedown"));
}),
(b._touchMove = function(a) {
e && ((this._touchMoved = !0), f(a, "mousemove"));
}),
(b._touchEnd = function(a) {
e &&
(f(a, "mouseup"),
f(a, "mouseout"),
this._touchMoved || f(a, "click"),
(e = !1));
}),
(b._mouseInit = function() {
var b = this;
b.element.bind({
touchstart: a.proxy(b, "_touchStart"),
touchmove: a.proxy(b, "_touchMove"),
touchend: a.proxy(b, "_touchEnd")
}),
c.call(b);
}),
(b._mouseDestroy = function() {
var b = this;
b.element.unbind({
touchstart: a.proxy(b, "_touchStart"),
touchmove: a.proxy(b, "_touchMove"),
touchend: a.proxy(b, "_touchEnd")
}),
d.call(b);
});
}
})(jQuery);
/* *** end jQuery UI Touch Punch *** */
var tileArr = [];
var ansID = ["6", "8", "1", "2", "7", "4", "3", "5"];
var droppedID = [0, 0, 0, 0, 0, 0, 0, 0];
var dragThis = 0;
var dropThis = 0;
$(document).ready(function() {
$(".tile").each(function() {
$(this).draggable({
drag: function(event, ui) {
dragThis = $(this).attr("id");
console.log(droppedID);
}
});
});
$(".blank").each(function() {
$(this).droppable({
drop: function(event, ui) {
$(this).addClass("ui-state-highlight");
dropThis =
$(this)
.attr("id")
.substring(2, 1) - 1;
droppedID[dropThis] = dragThis;
},
out: function(event, ui) {
$(this).removeClass("ui-state-highlight");
droppedID[dropThis] = 0;
}
});
});
$("button").click(function() {
var c = 0;
$(".blank").each(function(obj, value) {
if ($(this).hasClass("ui-state-highlight")) {
//do nothing
} else {
c++;
}
});
if (c > 0) {
$("#alert").html("Please place all tiles!");
} else {
var w = 0;
$.each(ansID, function(obj, value) {
if (value == droppedID[obj]) {
w++;
}
if (w == 8) {
puzzlerSolved = true;
$("#alert").html("You solved it!");
//unlock 1st padlock once puzzle is solved
// checkPadlocks('padlock0',puzzlerSolved);
// document.querySelector('.unlocked').setAttribute('fill', "#22a0b6");
document.querySelector("#padlock0 .locked").style.opacity = "0";
document.querySelector("#padlock0 .unlocked").style.opacity = "1";
//$("#alert").html(`You win! ${puzzlerSolved}`);
//console.log(puzzlerSolved); //done- trigger worked
} else {
$("#alert").html("Sorry please try again!");
puzzlerSolved = false;
}
//unlock 1st padlock once puzzle is solved
// puzzlerSolved= true;
// checkPadlocks('padlock0',puzzlerSolved);
});
}
});
});
// End JS for Puzzler Puzzle
document.querySelector(".revealtext").onclick = function() {
document.querySelector(".revealtext").style.backgroundColor = "transparent";
};
// End Cheryl Velez - Puzzler
// Dominic Duffin - Math Puzzle
// Get the modal
var mathPuzzleModal = document.getElementById("mathPuzzleModal");
// Get the button that opens the modal
var mathPuzzleBtn = document.getElementById("mathPuzzleBtn");
// Get the <span> element that closes the modal
var closeMathPuzzle = document.getElementsByClassName("close-mathpuzzle")[0];
// When the user clicks the button, open the modal
mathPuzzleBtn.onclick = function() {
mathPuzzleModal.style.display = "grid";
};
// When the user clicks on <span> (x), close the modal and check whether all puzzles solved
closeMathPuzzle.onclick = function() {
mathPuzzleModal.style.display = "none";
verify();
};
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == mathPuzzleModal) {
mathPuzzleModal.style.display = "none";
}
};
// Begin Math Puzzle JavaScript (not modal)
// TODO Replace window.alerts with something else!
var positionA; //A-G store value assigned to positions in sum
var positionB;
var positionC;
var positionD;
var positionE; //F doesn't exist because = is hard wired for F.
var positionG;
var choice; //Stores value of button last pressed by user
var bPlus = true; //Switch to false if user selects minus for B
var dPlus = true; //Switch to false if user selects minus for D
var sumTotal; //Stores correct sum for comparison with final position
//Messages:
function invalidMessage() {
document.getElementById("math-puzzle-message").innerHTML =
"Sorry, your choice is invalid!";
}
function fullMessage() {
document.getElementById("math-puzzle-message").innerHTML =
"Sorry, there are no more positions to fill!";
}
function solvedMessage() {
document.getElementById("math-puzzle-message").innerHTML =
"Yay, you've solved this one!";
}
function wrongMessage() {
document.getElementById("math-puzzle-message").innerHTML =
"Oh no, you got it wrong, better try again!";
}
function resetMathPuzzle() {
positionA = void 0;
positionB = void 0;
positionC = void 0;
positionD = void 0;
positionE = void 0;
positionG = void 0;
document.getElementById("math-puzzle-a").innerHTML = "Number";
document.getElementById("math-puzzle-b").innerHTML = "Sign";
document.getElementById("math-puzzle-c").innerHTML = "Number";
document.getElementById("math-puzzle-d").innerHTML = "Sign";
document.getElementById("math-puzzle-e").innerHTML = "Number";
document.getElementById("math-puzzle-g").innerHTML = "Number";
}
function checkNumber(x) {
//Returns true if x is a number 0 ≥ x ≤ 9
for (var i = 0; i < 10; i++) {
if (x == i) {
var y = true;
i = 10; //To stop loop
} else {
var y = false;
}
}
return y;
}
function checkSign(x) {
//Returns true if x is '+' or '-'
if (x == "+" || x == "-") {
var y = true;
} else {
var y = false;
}
return y;
}
//The assignPosition functions assign the user's choice to the position's var, after checking for validity.
function assignPositionA() {
isChoiceValid = checkNumber(choice);
if (isChoiceValid == true) {
positionA = choice;
document.getElementById("math-puzzle-a").innerHTML = choice;
} else {
invalidMessage();
}
}
function assignPositionB() {
isChoiceValid = checkSign(choice);
if (isChoiceValid == true) {
positionB = choice;
document.getElementById("math-puzzle-b").innerHTML = choice;
if (choice == "-") {
bPlus = false;
//console.log(bPlus);
}
} else {
invalidMessage();
}
}
function assignPositionC() {
isChoiceValid = checkNumber(choice);
if (isChoiceValid == true) {
positionC = choice;
document.getElementById("math-puzzle-c").innerHTML = choice;
} else {
invalidMessage();
}
}
function assignPositionD() {
isChoiceValid = checkSign(choice);
if (isChoiceValid == true) {
positionD = choice;
document.getElementById("math-puzzle-d").innerHTML = choice;
if (choice == "-") {
dPlus = false;
//console.log(dPlus);
}
} else {
invalidMessage();
}
}
function assignPositionE() {
isChoiceValid = checkNumber(choice);
if (isChoiceValid == true) {
positionE = choice;
document.getElementById("math-puzzle-e").innerHTML = choice;
} else {
invalidMessage();
}
}
function assignPositionG() {
//Also calls calculate function
isChoiceValid = checkNumber(choice);
if (isChoiceValid == true) {
positionG = choice;
document.getElementById("math-puzzle-g").innerHTML = choice;
calculateSumTotal();
} else {
invalidMessage();
}
}
function findEmptyPosition() {
//Finds the first unfilled position
if (positionA == undefined) {
assignPositionA();
} else if (positionB == undefined) {
assignPositionB();
} else if (positionC == undefined) {
assignPositionC();
} else if (positionD == undefined) {
assignPositionD();
} else if (positionE == undefined) {
assignPositionE();
} else if (positionG == undefined) {
assignPositionG();
} else {
fullMessage();
}
}
//The clicked functions record button presses by user
function oneClicked() {
choice = 1;
findEmptyPosition();
}
function twoClicked() {
choice = 2;
findEmptyPosition();
}
function threeClicked() {
choice = 3;
findEmptyPosition();
}
function fourClicked() {
choice = 4;
findEmptyPosition();
}
function fiveClicked() {
choice = 5;
findEmptyPosition();
}
function sixClicked() {
choice = 6;
findEmptyPosition();
}
function sevenClicked() {
choice = 7;
findEmptyPosition();
}
function eightClicked() {
choice = 8;
findEmptyPosition();
}
function nineClicked() {
choice = 9;
findEmptyPosition();
}
function zeroClicked() {
choice = 0;
findEmptyPosition();
}
function plusClicked() {
choice = "+";
findEmptyPosition();
}
function minusClicked() {
choice = "-";
findEmptyPosition();
}
function calculateSumTotal() {
//Calculates correct total
if (bPlus == true && dPlus == true) {
sumTotal = positionA + positionC + positionE;
} else if (bPlus == true && dPlus == false) {
sumTotal = positionA + positionC - positionE;
} else if (bPlus == false && dPlus == true) {
sumTotal = positionA - positionC + positionE;
} else if (bPlus == false && dPlus == false) {
sumTotal = positionA - positionC - positionE;
}
endGame();
}
function endGame() {
//Checks whether user is correct
if (sumTotal == positionG) {
solvedMessage();
mathPuzzleSolved = true; // Global var
//unlock 2nd lock
// checkPadlocks('padlock1',mathPuzzleSolved);
// document.querySelector('.unlocked').setAttribute('fill', "#cb0c59");
document.querySelector("#padlock1 .locked").style.opacity = "0";
document.querySelector("#padlock1 .unlocked").style.opacity = "1";
} else {
wrongMessage();
resetMathPuzzle();
}
}
//Tests for checkNumber
//var output = checkNumber(0);
//console.log(output); //true
//output = checkNumber(-1);
//console.log(output); //false
//output = checkNumber(9);
//console.log(output); //true
//output = checkNumber(10);
//console.log(output); //false
//output = checkNumber('+');
//console.log(output); //false
//Tests for checkSign:
//var output = checkSign('+');
//console.log(output); //true
//output = checkSign('-');
//console.log(output); //true
//output = checkSign(8);
//console.log(output); //false
//Tests for assignPosition functions:
//choice = 5;
//assignPositionA();
//assignPositionB(); //invalid
//assignPositionC();
//assignPositionD(); //invalid
//assignPositionE();
//assignPositionG();
//choice = '+';
//assignPositionA(); //invalid
//assignPositionB();
//assignPositionC(); //invalid
//assignPositionD();
//assignPositionE(); //invalid
//assignPositionG(); //invalid
//Tests for calculateSumTotal:
//bPlus = true;
//dPlus = true;
//positionA = 1;
//positionC = 2;
//positionE = 4;
//calculateSumTotal();
//console.log(sumTotal) //7
//bPlus = true;
//dPlus = false;
//positionA = 4;
//positionC = 2;
//positionE = 6;
//calculateSumTotal();
//console.log(sumTotal) //0
//bPlus = false;
//dPlus = true;
//positionA = 1;
//positionC = 2;
//positionE = 4;
//calculateSumTotal();
//console.log(sumTotal) //3
//bPlus = false;
//dPlus = false;
//positionA = 1;
//positionC = 1;
//positionE = 1;
//calculateSumTotal();
//console.log(sumTotal) //-1
//Tests for endGame:
//sumTotal = 9;
//positionG = 9;
//endGame(); //You win!
//sumTotal = 0;
//positionG = 9;
//endGame(); //Oh no, you're wrong!
document
.getElementById("math-puzzle-one")
.addEventListener("click", oneClicked, false);
document
.getElementById("math-puzzle-two")
.addEventListener("click", twoClicked, false);
document
.getElementById("math-puzzle-three")
.addEventListener("click", threeClicked, false);
document
.getElementById("math-puzzle-four")
.addEventListener("click", fourClicked, false);
document
.getElementById("math-puzzle-five")
.addEventListener("click", fiveClicked, false);
document
.getElementById("math-puzzle-six")
.addEventListener("click", sixClicked, false);
document
.getElementById("math-puzzle-seven")
.addEventListener("click", sevenClicked, false);
document
.getElementById("math-puzzle-eight")
.addEventListener("click", eightClicked, false);
document
.getElementById("math-puzzle-nine")
.addEventListener("click", nineClicked, false);
document
.getElementById("math-puzzle-zero")
.addEventListener("click", zeroClicked, false);
document
.getElementById("math-puzzle-plus")
.addEventListener("click", plusClicked, false);
document
.getElementById("math-puzzle-minus")
.addEventListener("click", minusClicked, false);
// End Math Puzzle JavaScript
// End Dominic Duffin - Math Puzzle
// `Paul` - Flexbox Puzzle
// Get the modal
var flexboxPuzzleModal = document.getElementById("flexboxPuzzleModal");
// Get the button that opens the modal
var flexboxPuzzleBtn = document.getElementById("flexboxPuzzleBtn");
// Get the <span> element that closes the modal
var closeFlexboxPuzzle = document.getElementsByClassName(
"close-flexboxpuzzle"
)[0];
// When the user clicks the button, open the modal
flexboxPuzzleBtn.onclick = function() {
flexboxPuzzleModal.style.display = "grid";
};
// When the user clicks on <span> (x), close the modal adn check whether all puzzles solved
closeFlexboxPuzzle.onclick = function() {
flexboxPuzzleModal.style.display = "none";
verify();
};
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == flexboxPuzzleModal) {
flexboxPuzzleModal.style.display = "none";
}
};
//define all variables used
let i = 0;
let subTitle = document.getElementsByClassName("heading__subtitle");
let displayFlex = document.getElementById("flexDisplay");
let directionOfFlex = document.getElementById("flexDirectn");
let justContent = document.getElementById("flexJustCont");
let flexAlign = document.getElementById("flexAlignItems");
let notification = document.querySelector(".notification");
let cubes = document.getElementsByClassName("cubes");
const containerClass = document.getElementsByClassName("flexPuzzle-container");
const flexDirections = ["row", "row-reverse", "column", "column-reverse"];
const flexJustifyContent = [
"flex-start",
"flex-end",
"center",
"space-between",
"space-around",
"space-evenly"
];
const flexAlignArray = [
"stretch",
"center",
"flex-start",
"flex-end",
"baseline"
];
//buttons event listener
displayFlex.addEventListener("click", function() {
if (containerClass[0].style.display == "block") {
containerClass[0].style.display = "flex";
displayFlex.innerHTML = "flex";
//add space on cubes when flex is on
for (i = 0; i < 5; i++) {
cubes[i].style.padding = "125px";
}
} else {
containerClass[0].style.display = "block";
displayFlex.innerHTML = "Display Flex";
//bring back original padding size on each cube
for (i = 0; i < 5; i++) {
cubes[i].style.padding = "15px";
}
}
checkPuzzle();
});
let itemLength = flexDirections.length;
directionOfFlex.addEventListener("click", function() {
// console.log(this.textContent);
subTitle[0].innerHTML =
"The flex-direction CSS property specifies how flex items are placed in the flex container defining the main axis and the direction (normal or reversed).";
if (i <= itemLength) {
this.textContent = flexDirections[i];
containerClass[0].style.flexDirection = flexDirections[i];
i++;
if (
document.querySelector(".flexPuzzle-container").style.flexDirection ===
"column-reverse"
) {
document.querySelector(".flexPuzzle-container").style.top = "1100px";
document.querySelector("#flexboxPuzzleModal .modal-content").style.height =
"1300px";
}
if (
document.querySelector(".flexPuzzle-container").style.flexDirection ===
"column"
) {
document.querySelector("#flexboxPuzzleModal .modal-content").style.height =
"1300px";
}
}
if (i > itemLength) {
document.querySelector("#flexboxPuzzleModal .modal-content").style.height =
"745px";
document.querySelector(".flexPuzzle-container").style.top = "300px";
this.textContent = "Change Flex Direction";
containerClass[0].style.flexDirection = "row";
i = 0;
}
checkPuzzle();
});
let itemJustifyContLength = flexJustifyContent.length;
justContent.addEventListener("click", function() {
// console.log(subTitle[0].innerHTML);
subTitle[0].innerHTML =
"justify-content property defines how the browser distributes space between and around content items along the main-axis of their container.";
if (i <= itemJustifyContLength) {
this.textContent = flexJustifyContent[i];
containerClass[0].style.justifyContent = flexJustifyContent[i];
i++;
}
if (i > itemJustifyContLength) {
this.textContent = "Change Flex Direction";
containerClass[0].style.justifyContent = "flex-start";
i = 0;
}
checkPuzzle();
});
let itemAlignmentArrayLen = flexAlignArray.length;
let midItem = document.getElementsByClassName("cubes");
flexAlign.addEventListener("click", function() {
// console.log(midItem[2].innerHTML);
subTitle[0].innerHTML =
"This controls the alignment of items on the Cross Axis.";
if (i <= itemAlignmentArrayLen) {
this.textContent = flexAlignArray[i];
containerClass[0].style.alignItems = flexAlignArray[i];
i++;
}
if (i > itemAlignmentArrayLen) {
this.textContent = "Change Flex Direction";
containerClass[0].style.alignItems = "flex-start";
midItem[2].classList.remove("itemHeight");
i = 0;
}
checkPuzzle();
});
function checkPuzzle() {
if (displayFlex.innerHTML === "flex") {
document.querySelectorAll(".front")[0].style.backgroundColor = "#7b1346";
// document.querySelectorAll('.side')[0]].style.backgroundColor = '#7b1346';
document.querySelectorAll(".left")[0].style.backgroundColor = "#7b1346";
document.querySelectorAll(".right")[0].style.backgroundColor = "#7b1346";
document.querySelectorAll(".bottom")[0].style.backgroundColor = "#7b1346";
document.querySelectorAll(".top")[0].style.backgroundColor = "#7b1346";
document.querySelectorAll(".back")[0].style.backgroundColor = "#7b1346";
notification.innerHTML = "Keep going! Try changing flex direction now.";
notification.style.color = "#0c4383";
checkDirection();
} else {
document.querySelectorAll(".front")[0].style.backgroundColor = "#0c4383";
// document.querySelectorAll('.side')[0].style.backgroundColor = '#0c4383';
document.querySelectorAll(".left")[0].style.backgroundColor = "#0c4383";
document.querySelectorAll(".right")[0].style.backgroundColor = "#0c4383";
document.querySelectorAll(".bottom")[0].style.backgroundColor = "#0c4383";
document.querySelectorAll(".top")[0].style.backgroundColor = "#0c4383";
document.querySelectorAll(".back")[0].style.backgroundColor = "#0c4383";
notification.innerHTML = 'Start with turning on "Display Flex"';
notification.style.color = "#E6E6E6";
}
checkAllButtons();
}
function checkDirection() {
if (displayFlex.innerHTML == "flex" && directionOfFlex.innerHTML == "row") {
document.querySelectorAll(".front")[4].style.backgroundColor = "#7b1346";
// document.querySelectorAll('.side')[4].style.backgroundColor = '#7b1346';
document.querySelectorAll(".left")[4].style.backgroundColor = "#7b1346";
document.querySelectorAll(".right")[4].style.backgroundColor = "#7b1346";
document.querySelectorAll(".bottom")[4].style.backgroundColor = "#7b1346";
document.querySelectorAll(".top")[4].style.backgroundColor = "#7b1346";
document.querySelectorAll(".back")[4].style.backgroundColor = "#7b1346";
notification.innerHTML = "Ok now, keep going...";
notification.style.color = "#0c4383";
checkJustifyContent();
} else {
document.querySelectorAll(".front")[4].style.backgroundColor = "#0c4383";
// document.querySelectorAll('.side')[4].style.backgroundColor = '#0c4383';
document.querySelectorAll(".left")[4].style.backgroundColor = "#0c4383";
document.querySelectorAll(".right")[4].style.backgroundColor = "#0c4383";
document.querySelectorAll(".bottom")[4].style.backgroundColor = "#0c4383";
document.querySelectorAll(".top")[4].style.backgroundColor = "#0c4383";
document.querySelectorAll(".back")[4].style.backgroundColor = "#0c4383";
}
}
function checkJustifyContent() {
if (
displayFlex.innerHTML == "flex" &&
directionOfFlex.innerHTML == "row" &&
justContent.innerHTML == "center"
) {
document.querySelectorAll(".front")[1].style.backgroundColor = "#7b1346";
// document.querySelectorAll('.side')[1].style.backgroundColor = '#7b1346';
document.querySelectorAll(".left")[1].style.backgroundColor = "#7b1346";
document.querySelectorAll(".right")[1].style.backgroundColor = "#7b1346";
document.querySelectorAll(".bottom")[1].style.backgroundColor = "#7b1346";
document.querySelectorAll(".top")[1].style.backgroundColor = "#7b1346";
document.querySelectorAll(".back")[1].style.backgroundColor = "#7b1346";
document.querySelectorAll(".front")[3].style.backgroundColor = "#7b1346";
// document.querySelectorAll('.side')[3].style.backgroundColor = '#7b1346';
document.querySelectorAll(".left")[3].style.backgroundColor = "#7b1346";
document.querySelectorAll(".right")[3].style.backgroundColor = "#7b1346";
document.querySelectorAll(".bottom")[3].style.backgroundColor = "#7b1346";
document.querySelectorAll(".top")[3].style.backgroundColor = "#7b1346";
document.querySelectorAll(".back")[3].style.backgroundColor = "#7b1346";
notification.innerHTML = "Hmm, you're getting hotter.";
notification.style.color = "#0d4383";
checkAllButtons();
} else {
document.querySelectorAll(".front")[1].style.backgroundColor = "#0c4383";
// document.querySelectorAll('.side')[1].style.backgroundColor = '#0c4383';
document.querySelectorAll(".left")[1].style.backgroundColor = "#0c4383";
document.querySelectorAll(".right")[1].style.backgroundColor = "#0c4383";
document.querySelectorAll(".bottom")[1].style.backgroundColor = "#0c4383";
document.querySelectorAll(".top")[1].style.backgroundColor = "#0c4383";
document.querySelectorAll(".back")[1].style.backgroundColor = "#0c4383";
document.querySelectorAll(".front")[3].style.backgroundColor = "#0c4383";
// document.querySelectorAll('.side')[3].style.backgroundColor = '#0c4383';
document.querySelectorAll(".left")[3].style.backgroundColor = "#0c4383";
document.querySelectorAll(".right")[3].style.backgroundColor = "#0c4383";
document.querySelectorAll(".bottom")[3].style.backgroundColor = "#0c4383";
document.querySelectorAll(".top")[3].style.backgroundColor = "#0c4383";
document.querySelectorAll(".back")[3].style.backgroundColor = "#0c4383";
notification.innerHTML = "Ok now, keep going...";
}
}
function checkAllButtons() {
if (
displayFlex.innerHTML == "flex" &&