123

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              	<!-- Memory game created by Lynda Naclerio under a tree, summer 2018 -->
	<!-- With thanks to Marina Ferreira and Free Code Camp -->
<div class="wrapper">
	<header class="header">
	  <h1>Tails From The Backyard - The Memory Game!</h1>
	</header>
	<section class="memory-game">
		<div class="memory-card" data-framework="Lynda">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Lynda.png" alt="Lynda">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="Lynda">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Lynda.png" alt="Lynda">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="The Slinky One">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Slinky.png" alt="The Slinky One">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="The Slinky One">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Slinky.png" alt="The Slinky One">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="The Fluffy One">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Fluffy.png" alt="The Fluffy One">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="The Fluffy One">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Fluffy.png" alt="The Fluffy One">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="The Puppy">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Puppy.png" alt="The Puppy">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="The Puppy">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Puppy.png" alt="The Puppy">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="Spider">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Spider.png" alt="Spider">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="Spider">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Spider.png" alt="Spider">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="Critters">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Critters.png" alt="Critters">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
		<div class="memory-card" data-framework="Critters">
			<img class="front-face" src="http://rzambrana.com/lynda/memory-game/img/Critters.png" alt="Critters">
			<img class="back-face" src="http://rzambrana.com/lynda/memory-game/img/Back.png" alt="Memory Card">
		</div>
	</section>
	<script src="scripts.js"></script>
	<footer class="footer">
		<p>Reload to play again - it's a work in progress!</p>
	    <p>Feedback? Contact: <a href="mailto:LyndaTheMonkey@Gmail.com">
	  LyndaTheMonkey@Gmail.com</a>.</p>
	</footer>
</div>
            
          
!
            
              * {
	padding: 0;
	margin: 0;
	box-sizing: border-box;
}

body {
	/*height: 100vh;*/
	display: flex;
	background: #e6f3d8;
	overflow: hidden;
}

h1 { font-family: Arial, Helvetica, sans-serif; color: #666; font-size: 20px; font-style: normal; font-variant: normal; font-weight: 700; line-height: 25px; margin-top: 5px; }

p { font-family: Arial, Helvetica, sans-serif; color: #666; font-size: 12px; font-style: normal; font-variant: normal; font-weight: 400; line-height: 14px; text-align: center;} 

.wrapper {
	margin: auto;
	display: flex;
	flex-direction: column;
}
/*flex-item {
	flex: 1;
}

flex-container {
	flex-direction: row;
	flex-wrap: nowrap;
	justify-content: flex-start;
	align-items: stretch;
}
*/
.memory-game {
	width: 600px;
	height: 90%;
	display: flex;
	flex-wrap: wrap;
	perspective: 1000px;
	min-height: calc(100vh - 70px);
}

.memory-card {
	width: calc(25% - 10px);
	height: calc(33.333%; -10px);
	margin: 5px;
	position: relative;
	transform: scale(1);
	transform-style: preserve-3d;
	transition: transform .5s;
}

.memory-card:active {
	transform: scale(.97);
	transition: transform .2s;
}

.memory-card.flip {
	transform: rotateY(180deg);
}

.front-face,
.back-face {
	width: 100%;
	height: 100%;
	padding: 20px;
	position: absolute;
	border-radius: 5px;
	background: #699a32;
	backface-visibility: hidden;
}

.front-face {
	transform: rotateY(180deg);
}

.header, .footer {
	height: 30px;
	margin: auto;
}
            
          
!
            
              const cards = document.querySelectorAll('.memory-card');

let hasFlippedCard = false;
let lockBoard = false;
let firstCard, secondCard;

function flipCard() {
	if (lockBoard) return;
	if (this === firstCard) return;

	this.classList.add('flip');

	if (!hasFlippedCard) {
		// first click
		hasFlippedCard = true;
		firstCard = this;

		return;
	}

	// second click
	secondCard = this;

	checkForMatch();
}

function checkForMatch() {
	// do cards match?
	let isMatch = firstCard.dataset.framework === secondCard.dataset.framework;

	isMatch ? disableCards() : unflipCards();
}

function disableCards() {
		// it's a match!
		firstCard.removeEventListener('click', flipCard);
		secondCard.removeEventListener('click', flipCard);

		resetBoard();
}

function unflipCards() {
	// not a match
	lockBoard = true;
	setTimeout(() => {
		firstCard.classList.remove('flip');
		secondCard.classList.remove('flip');

		resetBoard();
	}, 1500);

}

function resetBoard () {
	[hasFlippedCard, lockBoard] = [false, false];
	[firstCard, secondCard] = [null, null];
}


(function shuffle() {
	cards.forEach(card => {
		let randomPos = Math.floor(Math.random() * 12);
		card.style.order = randomPos;
	});
})();


cards.forEach(card => card.addEventListener('click', flipCard));
            
          
!
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.

Console