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 clearfix">
  <div class="dashboard">
    <div class="controls">
      <!--       <span class="control-button again">Play Again</span> -->
      <span class="target-color"></span>
    </div>
    <div class="playing-field"></div>
  </div>
  <div class="processed">
    <h2>Yay! ☺</h2>
  </div>
</div>

<audio src="http://soundbible.com/grab.php?id=480&type=wav"></audio>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

.wrapper {
  max-width: 400px;
  margin: 0 auto;
  text-align: center;
}

.clearfix:after {
  content: "";
  display: table;
  clear: both;
}

.clear {
  color: #fff;
}

.controls {
  padding: 10px;
  display: inline-block;
  width: 100%;
}

.control-button {
  padding: 10px 20px;
  background-color: #999;
}

.playing-field {
  display: inline-block;
  padding: 5px;
}

.square {
  display: inline-block;
  height: 60px;
  width: 60px;
  margin: 8px;
  border-radius: 10px;
  transition: all 250ms;
}

.unclicked {
  background-color: #708090;
}

.processed {
  vertical-align: top;
  border: 1px solid #eee;
  border-radius: 5px;
  display: inline-block;
  width: 100%;
  padding: 10px;
  webkit-box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.2);
  -moz-box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.2);
  box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.2);
}

.active,
.inactive {
  background-size: cover;
  background-position: center;
}

.processed h2 {
  transform: scale(0);
  transition: all 250ms;
}

.clicked {
  background-color: #b8c6d1;
  height: 25px;
  width: 25px;
  border-radius: 5px;
  margin: 3px;
}

.target-color {
  height: 60px;
  width: 100px;
  background-color: #666;
  display: inline-block;
  border: 4px solid #666;
  background-size: cover;
  background-position: top;
}

.flip {
  transform: rotateX(180deg);
}

@keyframes grow {
  0% {
    transform: scale(0);
  }
  20% {
    transform: scale(1.2);
  }
  30% {
    transform: scale(.8);
  }
  40% {
    transform: scale(1);
  }
  100% {
    transform: scale(1);
  }
}

.popup {
  animation: grow 1s ease-in;
}

@media (max-width: 480px) {
  .wrapper {
    text-align: center;
  }
  .processed,
  .dashboard {
    width: 100%;
    float: none;
  }
  .playing-field {
    margin: 0 0 10px;
  }
}
              
            
!

JS

              
                var color;

$(document).ready(function() {
  setSquares();
  $('.active').css('background-image', background);
  $('.inactive').css('background-image', decoy);
  $('.target-color').css('background-image', background);
});

function clicked(target) {
  if ($(target).hasClass('active')) {
    $(target).addClass('flip');
    $(target).removeClass('active').css({'background-color': '#708090', 'background-image': 'none'});
    if ($('.playing-field .active').length < 1) {
      $('.processed h2').addClass('popup');
      var delay = 1000; //1 second

      setTimeout(function() {
        setSquares();
        $('.processed h2').removeClass('popup');
      }, delay);
    }
  }
}

$('.again').click(function() {
  setSquares();
});

function clearField() {
  $('.playing-field .square').remove();
}

function setSquares() {
  clearField();
  for (var i = 0; i < 12; i++) {
    $('.playing-field').append('<span class="square unclicked" onClick="clicked(this)"></span>');
  }
  assignSquares();
  setColor();
  setDecoy();
}

function assignSquares() {
  var count = $(".playing-field .square").length;
  var squares = $('.playing-field .square');
  for (var i = 0; i <= count; i++) {
    var currentSquare = squares[i];
    var rand = Math.floor((Math.random() * 10) + 1);
    if (rand > 5) {
      $(currentSquare).addClass('active');
    } else {
      $(currentSquare).addClass('inactive');
    }
  }
}

function setDecoy() {
  var rand = Math.floor((Math.random() * 10) + 1);
  if (rand <= 2) {
    decoy = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/011.png)';
  } else if ((rand > 2) && (rand <= 4)) {
    decoy = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/018.png)';
  } else if (rand > 4 && rand <= 6) {
    decoy = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/042.png';
  } else if (rand > 6 && rand <= 8) {
    decoy = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/047.png';
  } else {
    decoy = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/019.png';
  }
  $('.inactive').css('background-image', decoy);
  return decoy;
}

function setColor() {
  var rand = Math.floor((Math.random() * 10) + 1);
  if (rand <= 2) {
    background = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/006.png)';
  } else if ((rand > 2) && (rand <= 4)) {
    background = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/025.png)';
  } else if (rand > 4 && rand <= 6) {
    background = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/113.png';
  } else if (rand > 6 && rand <= 8) {
    background = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/175.png';
  } else {
    background = 'url(http://assets.pokemon.com/assets/cms2/img/pokedex/full/001.png';
  }
  $('.target-color').css('background-image', background);
  $('.active').css('background-image', background);
  return background;
}
              
            
!
999px

Console