Ledger Nano X - The secure hardware wallet
SHARE
TWEET

01.Cards

a guest Aug 10th, 2019 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.    let cards = document.getElementsByTagName('img');
  3.  
  4.    let upperCard = 0;
  5.    let upperCardNode;
  6.    let bottomCard = 0;
  7.    let bottomCardNode;
  8.  
  9.    for (const card of cards) {
  10.       card.addEventListener('click', function(e) {
  11.          card.setAttribute('src', 'images/whiteCard.jpg')
  12.  
  13.          let parentID = this.parentNode.getAttribute('id');
  14.  
  15.          if (parentID === 'player1Div') {
  16.  
  17.             let span = document.querySelectorAll('#result span')[0];
  18.             let name = this.getAttribute('name');
  19.             upperCard = Number(name);
  20.             upperCardNode = this;
  21.             span.append(name);
  22.  
  23.          } else if (parentID === 'player2Div') {
  24.  
  25.             let span = document.querySelectorAll('#result span')[2];
  26.             let name = this.getAttribute('name');
  27.             bottomCard = Number(name);
  28.             bottomCardNode = this;
  29.             span.append(name);
  30.  
  31.          }
  32.          if (upperCard > bottomCard && upperCard !== 0 && bottomCard !== 0) {
  33.  
  34.             upperCardNode.style = 'border: 2px solid green';
  35.             bottomCardNode.style = 'border: 2px solid red';
  36.             document.getElementById('history').append(`[${upperCard} vs ${bottomCard}] `);
  37.             let spanUpRes = document.querySelectorAll('#result span')[0];
  38.             let spanDownRes = document.querySelectorAll('#result span')[2];
  39.             spanUpRes.innerHTML = '';
  40.             spanDownRes.innerHTML = '';
  41.             upperCard = 0;
  42.             bottomCard = 0;
  43.  
  44.          } else if (upperCard < bottomCard && upperCard !== 0 && bottomCard !== 0) {
  45.  
  46.             bottomCardNode.style = 'border: 2px solid green';
  47.             upperCardNode.style = 'border: 2px solid red';
  48.             document.getElementById('history').append(`[${upperCard} vs ${bottomCard}] `);
  49.             let spanUpRes = document.querySelectorAll('#result span')[0];
  50.             let spanDownRes = document.querySelectorAll('#result span')[2];
  51.             spanUpRes.innerHTML = '';
  52.             spanDownRes.innerHTML = '';
  53.             upperCard = 0;
  54.             bottomCard = 0;
  55.  
  56.          } else if (upperCard === bottomCard) {
  57.  
  58.             document.getElementById('history').append(`[${upperCard} vs ${bottomCard}] `);
  59.             let spanUpRes = document.querySelectorAll('#result span')[0];
  60.             let spanDownRes = document.querySelectorAll('#result span')[2];
  61.             spanUpRes.innerHTML = '';
  62.             spanDownRes.innerHTML = '';
  63.             upperCard = 0;
  64.             bottomCard = 0;  
  65.  
  66.          }
  67.       })
  68.    }  
  69. }
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