daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let res1 =  document.getElementById("result").children[0];
  3.     let res2 = document.getElementById("result").children[2];
  4.  
  5.     let cardOne;
  6.     let cardTwo;
  7.  
  8.     let playerOne = [...document.getElementById("player1Div").children];
  9.     playerOne.forEach(el => {
  10.         el.addEventListener('click', function () {
  11.             this.src = "./images/whiteCard.jpg";
  12.             document.getElementById("result").children[0].innerHTML = this.name;
  13.             cardOne = this;
  14.             getWinner();
  15.         })
  16.     });
  17.  
  18.     let playerTwo = [...document.getElementById("player2Div").children];
  19.     playerTwo.forEach(el => {
  20.         el.addEventListener('click', function () {
  21.             this.src = "./images/whiteCard.jpg";
  22.             document.getElementById("result").children[2].innerHTML = this.name;
  23.             cardTwo = this;
  24.             getWinner();
  25.         })
  26.     });
  27.  
  28.    function getWinner() {
  29.       if (res1.innerHTML !== "" && res2.innerHTML !== "") {
  30.           if (+res1.innerHTML > +res2.innerHTML) {
  31.             cardOne.style.border = "2px solid green";
  32.             cardTwo.style.border = "2px solid red";
  33.           } else {
  34.             cardOne.style.border = "2px solid red";
  35.             cardTwo.style.border = "2px solid green";
  36.           }
  37.  
  38.           document.getElementById("history").innerHTML += `[${res1.innerHTML} vs ${res2.innerHTML}] `;
  39.  
  40.           res1.innerHTML = "";
  41.           res2.innerHTML = "";
  42.       }
  43.    }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top