Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mind Game - Dhruv Majithiya</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <section class="center" id="center">
        <div class="parent" id="parent">
        </div>
    </section>
   <a href="https://imdhruv.netlify.app/" id="dhruv" target="_dhruv">Made By Dhruv Majithiya</a>
    <script src="script.js"></script>
</body>

</html>
              
            
!

CSS

              
                *,
*::after,
*::before {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
}

body {
  font-family: calibri;
  background: hsl(0, 0%, 93%);
  color: white;
  height: 100vh;
  display: grid;
  place-items: center;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

:root {
  --main-col: 5 20 40;
  --color: ;
  --bronze: 140 100 60;
  --silver: 192 192 192;
  --gold: 255 215 0;
}

.center {
  width: 100vw;
  padding: 0px 20px;
  margin: auto 0px;
}

.parent {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-column-gap: 10px;
  grid-row-gap: 10px;
  gap: 10px;
  place-items: center;
}

.silver {
  position: relative;
  width: 100% !important;
  height: 100% !important;
  max-height: 800px;
  overflow: hidden;
  background: rgb(var(--main-col));
  border-radius: .75rem;
  box-shadow: 0 15px 30px -5px rgba(255, 255, 255, 0.1);
  color: var(--color);
  display: grid;
  place-items: center;
}

.silver {
  --color: rgb(var(--gold));
}

.silver::before {
  content: '';
  width: 200%;
  aspect-ratio: 1/1;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center;
  background-image: conic-gradient(transparent, 270deg, currentColor, transparent);
  animation: rotate 3s linear infinite;
}

.silver::after {
  content: '';
  background: inherit;
  border-radius: inherit;
  position: absolute;
  inset: 5px;
  width: calc(100% - 10px);
  height: calc(100% - 10px);
}

@keyframes rotate {
  from {
    transform: translate(-50%, -50%) rotate(0);
  }

  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

.image_container {
  position: relative;
  z-index: 1;
  max-width: 100%;
  max-height: 100%;
  display: grid;
  place-items: center;
}

.image_container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.card {
  transform-style: preserve-3d !important;
  transition: transform 1s ease !important;
  cursor: pointer;
  width: 200px !important;
  height: 250px !important;
  transform: rotateY(180deg);
}

.card:hover {
  /* transform: rotateY(0deg); */
}

.front,
.back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
}

.back {
  color: white;
  transform: rotateY(180deg);
}

.back .silver {
  display: block;
}

.back .silver::after {
  position: static;
}

.back img {
  position: absolute;
  z-index: 1;
  object-fit: contain;
  max-width: 100%;
  width: 100%;
}

.win {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: 2s;
}

.win p {
  font-size: 4rem;
  font-weight: bold;
  color: black;
  margin-bottom: 20px;
}

.win button {
  background: black;
  padding: 10px;
  border-radius: 30px;
  color: white;
  border: none;
  width: 150px;
  height: 50px;
  font-size: 20px;
}
#dhruv{
  position: fixed;
  bottom: 10px;
  right: 10px;
  background-color: black;
  color: white;
  text-decoration: none;
  text-transform: capitalize;
  padding: 10px;
  border-radius: 10px;
}
              
            
!

JS

              
                element_1 = `<div class="card e1"><div class="front"><div class="silver"><div class="image_container"><img src="https://lh3.googleusercontent.com/-PqyqaV67CQs/ZZzDhAzo-EI/AAAAAAAAT70/oeWP4SOBLDQ-RKCmrr8EEp0ZV2jje6hdgCNcBGAsYHQ/h120/800px-HTML5_Badge.svg.png" alt=""></div></div></div><div class="back"><div class="silver"><img src="https://dmemory-game.netlify.app/front.jpg" alt="card front"></div></div><input type="hidden" value="false"></div>`;
element_2 = `<div class="card e2"><div class="front"><div class="silver"><div class="image_container"><img src="https://lh3.googleusercontent.com/-s25kAVNdQug/ZZzDhD9RhiI/AAAAAAAAT7w/jcip2QUpbjMpgdUhRdZs0rsDzht-8RfggCNcBGAsYHQ/h120/4672509.png" alt=""></div></div></div><div class="back"><div class="silver"><img src="https://dmemory-game.netlify.app/front.jpg" alt="card front"></div></div><input type="hidden" value="false"></div>`;
element_3 = `<div class="card e3"><div class="front"><div class="silver"><div class="image_container"><img src="https://lh3.googleusercontent.com/-tSyq-mmJ8AM/ZZzt6LtZxeI/AAAAAAAAT8o/rI3lidpNj74_hE3qCDRx2-MZMcTuZ1W4wCNcBGAsYHQ/h120/js.png" alt=""></div></div></div><div class="back"><div class="silver"><img src="https://dmemory-game.netlify.app/front.jpg" alt="card front"></div></div><input type="hidden" value="false"></div>`;
element_4 = `<div class="card e4"><div class="front"><div class="silver"><div class="image_container"><img src="https://lh3.googleusercontent.com/-OSBS721Rx5Q/ZZzDiFbOnxI/AAAAAAAAT8E/DlaYAtEMdvA3giLpG7M8_Yog-kkEnaipACNcBGAsYHQ/h120/unnamed.png" alt=""></div></div></div><div class="back"><div class="silver"><img src="https://dmemory-game.netlify.app/front.jpg" alt="card front"></div></div><input type="hidden" value="false"></div>`;
element_5 = `<div class="card e5"><div class="front"><div class="silver"><div class="image_container"><img src="https://lh3.googleusercontent.com/-JGJCXxqWaLY/ZZzt6S-_zJI/AAAAAAAAT8s/pH3-inHDO-I7c1NQxS8aUCqywUndEJWwwCNcBGAsYHQ/h120/pythonsd.png" alt=""></div></div></div><div class="back"><div class="silver"><img src="https://dmemory-game.netlify.app/front.jpg" alt="card front"></div></div><input type="hidden" value="false"></div>`;
element_6 = `<div class="card e6"><div class="front"><div class="silver"><div class="image_container"><img src="https://lh3.googleusercontent.com/-3VgMQDLutZs/ZZzDiMKiUvI/AAAAAAAAT8A/oIWdDKRnOt0o0IYh0LI_9IetZHrJk55jQCNcBGAsYHQ/h120/WordPress_blue_logo.svg.png" alt=""></div></div></div><div class="back"><div class="silver"><img src="https://dmemory-game.netlify.app/front.jpg" alt="card front"></div></div><input type="hidden" value="false"></div>`;
let myArray = [
  element_1,
  element_2,
  element_3,
  element_4,
  element_5,
  element_6,
  element_1,
  element_2,
  element_3,
  element_4,
  element_5,
  element_6,
];
let parent = document.getElementById("parent");
function shuffleArray(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [array[i], array[j]] = [array[j], array[i]];
  }
}
window.onload = function () {
  document.addEventListener("contextmenu", (event) => {
    event.preventDefault();
  });
  for (let i = 0; i < 12; i++) {
    var newArray = [...myArray];
    shuffleArray(newArray);
  }
  // console.log(`Shuffled Array :`, newArray);
  newArray.forEach((htmlString) => {
    parent.innerHTML += htmlString;
  });
  let imgs = document.getElementsByTagName('img'); 
  // https://dmemory-game.netlify.app/play.mp3
  const audio = new Audio('https://dmemory-game.netlify.app/play.mp3');
  Array.from(imgs).forEach(function (elm){elm.setAttribute("draggable", false)});
  let card_no = 0;
  let cards = document.querySelectorAll(".card");
  cards.forEach((card) => {
    card.addEventListener("click", function () {
      let flg = card.getElementsByTagName("input")[0];
      let answer = [];
      // card.style.transform= "rotateY(0deg)";
      let currentRotation =
        getComputedStyle(card).getPropertyValue("transform");
      // If the current rotation is 'none' or 'matrix(1, 0, 0, 1, 0, 0)', set it to 'rotateY(45deg)', otherwise set it to 'none'
      card.style.transform =
        currentRotation === "none" ||
        currentRotation === "matrix(1, 0, 0, 1, 0, 0)"
          ? "rotateY(180deg)"
          : "rotateY(0deg)";

      card_no++;
      flg.value == "false" ? (flg.value = "true") : (flg.value = "false");
      if (card_no == 2) {
        let classes = card.classList;
        class_name = classes[1];
        elem2 = document.getElementsByClassName(class_name);
        Array.from(elem2).forEach((e) => {
          let inputElement = e.getElementsByTagName("input")[0];
          answer.push(inputElement.value);
        });
        setTimeout(function () {
          if (answer[0] == "true" && answer[1] == "true") {
            Array.from(elem2).forEach((ep) => {
              ep.style.transform = "translateY(-100vh)";
            });
          }
        },600);
        setTimeout(function () {
          cards.forEach((card) => {
            let inflg = card.getElementsByTagName("input")[0];
            card.style.transform = "rotateY(180deg)";
            inflg.value == "true" ? (inflg.value = "false") : "true";
          });
          card_no = 0;
          if (answer[0] == "true" && answer[1] == "true") {
            Array.from(elem2).forEach((ep) => {
              // ep.style.display="none";
              ep.remove();
            });
              let center_add = document.getElementById("center");
              let card_parent = document.getElementById("parent");
              if(card_parent.childNodes.length == 1){
                center_add.innerHTML = `<div class="win"><p>Congratulations You Won!</p><button onclick="window.location.reload()" href="#">Play Again</button></div>`;
                audio.play();
              }
            answer.length = 0;
          } else {
            answer.length = 0;
          }
        }, 1000);
      }
    });
  });
};

              
            
!
999px

Console