vdjalov

Untitled

Jan 21st, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. function solve() {
  2.  
  3.  
  4. let linksPlayerOne = document.querySelectorAll("#player1Div img");
  5. let linksPlayerTwo = document.querySelectorAll("#player2Div img");
  6. let spans = document.querySelectorAll("#result span");
  7. let spanLeft = spans[0];
  8. let spanRight = spans[2];
  9. let currentLeftImage = "";
  10. let currentRightImage = "";
  11. let historyDiv = document.querySelector("#history");
  12. //Lower side
  13. linksPlayerTwo[0].addEventListener("click", () => {
  14. linksPlayerTwo[0].src = "../01_Cards/images/whiteCard.jpg";
  15. spanRight.textContent = linksPlayerTwo[0].name;
  16. currentRightImage = linksPlayerTwo[0];
  17. checkElement(currentLeftImage, currentRightImage);
  18. })
  19.  
  20. linksPlayerTwo[1].addEventListener("click", () => {
  21. linksPlayerTwo[1].src = "../01_Cards/images/whiteCard.jpg";
  22. spanRight.textContent = linksPlayerTwo[1].name;
  23. currentRightImage = linksPlayerTwo[1];
  24. checkElement();
  25. })
  26.  
  27. linksPlayerTwo[2].addEventListener("click", () => {
  28. linksPlayerTwo[2].src = "../01_Cards/images/whiteCard.jpg";
  29. spanRight.textContent = linksPlayerTwo[2].name;
  30. currentRightImage = linksPlayerTwo[2];
  31. checkElement();
  32. })
  33.  
  34. linksPlayerTwo[3].addEventListener("click", () => {
  35. linksPlayerTwo[3].src = "../01_Cards/images/whiteCard.jpg";
  36. spanRight.textContent = linksPlayerTwo[3].name;
  37. currentRightImage = linksPlayerTwo[3];
  38. checkElement();
  39. })
  40.  
  41. linksPlayerTwo[4].addEventListener("click", () => {
  42. linksPlayerTwo[4].src = "../01_Cards/images/whiteCard.jpg";
  43. spanRight.textContent = linksPlayerTwo[4].name;
  44. currentRightImage = linksPlayerTwo[4];
  45. checkElement();
  46. })
  47.  
  48. linksPlayerTwo[5].addEventListener("click", () => {
  49. linksPlayerTwo[5].src = "../01_Cards/images/whiteCard.jpg";
  50. spanRight.textContent = linksPlayerTwo[5].name;
  51. currentRightImage = linksPlayerTwo[5];
  52. checkElement();
  53. })
  54.  
  55. linksPlayerTwo[6].addEventListener("click", () => {
  56. linksPlayerTwo[6].src = "../01_Cards/images/whiteCard.jpg";
  57. spanRight.textContent = linksPlayerTwo[6].name;
  58. currentRightImage = linksPlayerTwo[6];
  59. checkElement();
  60. })
  61.  
  62. linksPlayerTwo[7].addEventListener("click", () => {
  63. linksPlayerTwo[7].src = "../01_Cards/images/whiteCard.jpg";
  64. spanRight.textContent = linksPlayerTwo[7].name;
  65. currentRightImage = linksPlayerTwo[7];
  66. checkElement();
  67. })
  68.  
  69. //Upper side
  70. linksPlayerOne[0].addEventListener("click", () => {
  71. linksPlayerOne[0].src = "../01_Cards/images/whiteCard.jpg";
  72. spanLeft.textContent = linksPlayerOne[0].name;
  73. currentLeftImage = linksPlayerOne[0];
  74. checkElement();
  75. })
  76.  
  77.  
  78. linksPlayerOne[1].addEventListener("click", () => {
  79. linksPlayerOne[1].src = "../01_Cards/images/whiteCard.jpg";
  80. spanLeft.textContent = linksPlayerOne[1].name;
  81. currentLeftImage = linksPlayerOne[1];
  82. checkElement();
  83. })
  84.  
  85.  
  86. linksPlayerOne[2].addEventListener("click", () => {
  87. linksPlayerOne[2].src = "../01_Cards/images/whiteCard.jpg";
  88. spanLeft.textContent = linksPlayerOne[2].name;
  89. currentLeftImage = linksPlayerOne[2];
  90. checkElement();
  91. })
  92.  
  93.  
  94. linksPlayerOne[3].addEventListener("click", () => {
  95. linksPlayerOne[3].src = "../01_Cards/images/whiteCard.jpg";
  96. spanLeft.textContent = linksPlayerOne[3].name;
  97. currentLeftImage = linksPlayerOne[3];
  98. checkElement();
  99. })
  100.  
  101. linksPlayerOne[4].addEventListener("click", () => {
  102. linksPlayerOne[4].src = "../01_Cards/images/whiteCard.jpg";
  103. spanLeft.textContent = linksPlayerOne[4].name;
  104. currentLeftImage = linksPlayerOne[4];
  105. checkElement();
  106. })
  107.  
  108. linksPlayerOne[5].addEventListener("click", () => {
  109. linksPlayerOne[5].src = "../01_Cards/images/whiteCard.jpg";
  110. spanLeft.textContent = linksPlayerOne[5].name;
  111. currentLeftImage = linksPlayerOne[5];
  112. checkElement();
  113. })
  114.  
  115. linksPlayerOne[6].addEventListener("click", () => {
  116. linksPlayerOne[6].src = "../01_Cards/images/whiteCard.jpg";
  117. spanLeft.textContent = linksPlayerOne[6].name;
  118. currentLeftImage = linksPlayerOne[6];
  119. checkElement();
  120. })
  121.  
  122. linksPlayerOne[7].addEventListener("click", () => {
  123. linksPlayerOne[7].src = "../01_Cards/images/whiteCard.jpg";
  124. spanLeft.textContent = linksPlayerOne[7].name;
  125. currentLeftImage = linksPlayerOne[7];
  126. checkElement();
  127. })
  128.  
  129. //
  130. function checkElement(){
  131. if(currentLeftImage !== "" && currentRightImage !== ""){
  132. if(+currentLeftImage.name < +currentRightImage.name){
  133. currentLeftImage.style.border = "2px solid red";
  134. currentRightImage.style.border = "2px solid green";
  135. } else {
  136. currentLeftImage.style.border = "2px solid green";
  137. currentRightImage.style.border = "2px solid red";
  138.  
  139. }
  140. historyDiv.append("["+spanLeft.textContent + " vs " + spanRight.textContent + "] ");
  141. currentLeftImage = "";
  142. currentRightImage = "";
  143. setTimeout(() => {
  144. spanLeft.textContent = "";
  145. spanRight.textContent = "";
  146.  
  147. }, 2000)
  148.  
  149. }
  150. }
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment