cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

            
              <div class="wrapper">

  <header class="header">
    <h1 class="header__title header__title--memory">
      <!-- <span class="header__title--ki">Ki</span><span class="header__title--o">o</span><span class="header__title--ku">Ku</span> -->
      <span class="header__title--mem">Mem</span><span class="header__title--o">o</span><span class="header__title--ry">ry</span>
      <h1 class="header__title header__title--game">Game</h1>
      </header>

    <main>
      <section class="bar">
        <div class="bar__score">
          <span class="bar__span">Moves:</span>
          <span class="bar__n" id="move-counter">0</span>
          <div class="bar__stars">
            <i class="fa fa-star" id="star-1">
            </i>
            <i class="fa fa-star" id="star-2"></i>
            <i class="fa fa-star" id="star-3"></i>
          </div>
        </div>
        <div class="bar__time" id="displayed-time">
          <time>
            00:00:00
          </time>
        </div>
        <button onclick="shuffleCards()">Shuffle</button>


      </section>

      <section class="cards" id="container">

        <div class="flip-container card" ontouchstart="flipCard(card)" id="1">
          <div class="flipper">
            <div class="card__front" id="front-1">
              <span class="span--hide ">1</span>
            </div>
            <div class="card__back">

            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="2">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">1</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="3">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">2</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="4">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">2</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>

        <div class="flip-container card" ontouchstart="flipCard(card)" id="5">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">3</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="6">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">3</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="7">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">4</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="8">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">4</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>

        <div class="flip-container card" ontouchstart="flipCard(card)" id="9">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">5</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="10">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">5</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="11">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">6</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="12">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">6</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>

        <div class="flip-container card" ontouchstart="flipCard(card)" id="13">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">7</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="14">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">7</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="15">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">8</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>
        <div class="flip-container card" ontouchstart="flipCard(card)" id="16">
          <div class="flipper">
            <div class="card__front">
              <span class="span--hide ">8</span>
            </div>
            <div class="card__back">
            </div>
          </div>
        </div>

      </section>
    </main>
    </div>


            
          
!
            
              /* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}
/*------------------------------------------------------------------------------*/

.cards {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    margin-top: 2em;
    width: 100%;
}

.card {
  margin: 1em;
  max-width: 100%;
}
.flip-container {
  -webkit-perspective: 1000px;
  perspective: 1000px;
}

/* flip card on hover */

.flip-container:hover {
  cursor: pointer;
}

.flip-container.hover .flipper {
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

.flip-container.hover-back .flipper {
  transform: rotateY(-180deg);
}

.flip-container,
.card__front,
.card__back {
    width: 6.5em;
    height: 6.5em;
}
 
/*flip speed*/
.flipper {
  -webkit-transition: 0.6s;
  transition: 0.6s;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  
  position: relative;
}

/* hide card__back during the swap */

.card__front,
.card__back {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
  border: 6px solid #000;
}

/* place card__front above card__back */

.card__front {
  z-index: 2;
  /* for firefox 31 */
  -webkit-transform: rotateY(0deg);
  transform: rotateY(0deg);
}
.card__front span,
.card__back span {
  font-size: 2em;
}
.card__back {
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
  background: #333;
}

/*
.span--hide {
    display: none;
}*/

button {
  margin: 1em;
  padding: 2em;
  font-size: 1em
}
button:hover {
  cursor: pointer;
}
#front-1 {
  background-color: green;
}
            
          
!
            
              const container = document.getElementById('container');
var cards = container.getElementsByClassName('card'),
    isFlipped = false,
    clickCount = '',
    touchCount = '';

for(let card of cards){
  card.addEventListener('click', function(){
    if(!isFlipped){
          flipCard(card);
          isFlipped = true;
    } else if(isFlipped){
      flipCardBack(card);
          isFlipped = false;
    }
  })
}


function handleTouch(card) {

  touchCount++;
  
  if (touchCount === 1) {
    flipCard(card);
  } else if (touchCount === 2){
    flipCardBack(card);
    touchCount = 0;
  }

}

function flipCard(element) {
  element.classList.add('hover');
}

function flipCardBack(element) {
  element.classList.remove('hover');
}

// 6. implement shuffle feature
function shuffleCards() {
    // convert Node list to array
    let arrayOfCards = nodeListToArray(cards);

    // remove cards from dom
    arrayOfCards.forEach(function (card) {
        container.removeChild(card);
    })

    // shuffle them
    shuffleArray(arrayOfCards);

    // put them back in the dom
    arrayOfCards.forEach(function (card) {
        container.appendChild(card);
    })
}

function nodeListToArray(nodeList) {
    let arr = [];

    for (let card of cards) {
        arr.push(card);
    }
    return arr.slice();
}

function shuffleArray(array) {
    for (let i = 0, n = array.length - 1; i < n; i++) {
        let random = Math.floor(Math.random() * (n + 1));

        let tmp = array[i];

        array[i] = array[random];

        array[random] = tmp;
    }

    return array;
}


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console