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

              
                <div class="wrapper">
  <h1>JavaScript pairs Game</h1>
  <h3>Click any card to begin</h3>
  <p><span id="seconds">00</span>:<span id="tens">00</span></p>
  <p id ="text"></p>
  <div id="container">

  </div>
</div>


              
            
!

CSS

              
                /* Variabes */  
$orange: #ffa600;
$green: #c1d72e;
$blue: #82d2e5;
$grey: #f3f3f3;
$white: #fff;
$base-color:$blue ;


/* Mixin's */  
@mixin transition {
  -webkit-transition: all 0.5s ease-in-out;
  -moz-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
}

@mixin corners ($radius) {
  -moz-border-radius: $radius;
  -webkit-border-radius: $radius;
  border-radius: $radius; 
  -khtml-border-radius: $radius; 
}

body {
  background:$base-color;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; 
  height:100%;
  color: $white;
  text-align: center;
}


h1, h2 {
  font-family: 'Roboto', sans-serif;
  font-weight: 100;
  font-size: 2.6em;
  text-transform: uppercase;
}

h3 {
  font-family: 'Roboto', sans-serif;
  font-weight: 100;
  font-size: 1.4em;
  text-transform: uppercase;
}

#seconds, #tens{
  font-size:2em;
}

button{
  @include corners (5px);
  background:$base-color;
  color:$white;
  border: solid 1px $white;
  text-decoration:none;
  cursor:pointer;
  font-size:1.2em;
  padding:18px 10px;
  width:180px;
  margin: 10px;
  outline: none;
 
    &:hover {
    	@include transition;
    	background:$white;
    	border: solid 1px $white;
    	color:$base-color;
  	}
    
}


#container {
  width: 630px;
  margin: 10px auto;

  &:after {
    content: "";
    display: table;
    clear: both;
  }
  
}

[data-view="card"] {
  transform: rotateY(180deg);
  width: 100px;
  height: 140px;
  border: solid 1px #d3cece;
  border-radius: 5px;
  float: left;
  margin: 10px;
  cursor: pointer;
  background:
  linear-gradient(135deg, $grey 22px, $white 22px, $white 24px, transparent 24px, transparent 67px, $white 67px, $white 69px, transparent 69px),
  linear-gradient(225deg, $grey 22px, $white 22px, $white 24px, transparent 24px, transparent 67px, $white 67px, $white 69px, transparent 69px)0 64px;
  background-color: $grey;
  background-size: 64px 128px
}

.flipped {
  transition: 0.6s;
	transform-style: preserve-3d;
  position: relative;
	transform: rotateY(0deg);
}

.reverse {
  transition: 0.6s;
	transform-style: preserve-3d;
  position: relative;
	transform: rotateY(180deg);
}

.correct {
  opacity: .5;
  cursor: default;
	transform-style: preserve-3d;
  position: relative;
	transform: rotateY(0deg);
}

/* Icons */
$cards: sass, gulp, grunt, git, css;
       
@each $card in $cards  {

  .correct[data-item="#{$card}"],
  .flipped[data-item="#{$card}"]{
    background:url("https://cathydutton.co.uk/images/tech/#{$card}.jpg") left center no-repeat $white;
    background-size: contain;
  }

}





              
            
!

JS

              
                var myCards = document.getElementById('container');
var resultsArray = [];
var counter = 0;
var text = document.getElementById('text');
var seconds = 00; 
var tens = 00; 
var appendTens = document.getElementById("tens");
var appendSeconds = document.getElementById("seconds");
var Interval ;
var images = [
  'sass', 
  'git', 
  'gulp', 
  'css', 
  'grunt'
];

var clone = images.slice(0); // duplicate array
var cards = images.concat(clone); // merge to arrays 

// Shufffel function
function shuffle(o){
  for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i],   o[i] = o[j], o[j] = x);
  return o;
}
shuffle(cards);

for (var i = 0; i < cards.length; i++) {
  card = document.createElement('div');
  card.dataset.item = cards[i];
  card.dataset.view = "card";
  myCards.appendChild(card);
     
  card.onclick = function () {
   
    if (this.className != 'flipped' && this.className != 'correct'){
        this.className = 'flipped';
        var result = this.dataset.item;
        resultsArray.push(result);
        clearInterval(Interval);
        Interval = setInterval(startTimer, 10);
    }
  
    if (resultsArray.length > 1) {

      if (resultsArray[0] === resultsArray[1]) {
        check("correct");
        counter ++;
        win();
        resultsArray = [];
      } else {
        check("reverse");
        resultsArray = [];
      }
      
    }
    
  }
   
};


var check = function(className) {
  
  var x = document.getElementsByClassName("flipped");
  setTimeout(function() {

    for(var i = (x.length - 1); i >= 0; i--) {
      x[i].className = className;
    }
     
  },500);
   
}

var win = function () {

  if(counter === 5) {
    clearInterval(Interval);
    text.innerHTML = "Your time was " + seconds + ":" + tens;
  } 
  
}
     
function startTimer () {
  tens++; 
    
  if(tens < 9){
    appendTens.innerHTML = "0" + tens;
  }
    
  if (tens > 9){
    appendTens.innerHTML = tens;
      
  } 
    
  if (tens > 99) {
    seconds++;
    appendSeconds.innerHTML = "0" + seconds;
    tens = 0;
    appendTens.innerHTML = "0" + 0;
  }
    
  if (seconds > 9){
    appendSeconds.innerHTML = seconds;
  }
  
}


              
            
!
999px

Console