Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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='head'>
	<div class='time'>Time: <span class="min">00</span>:<span class="sec">00</span></div>
	<div class='start'>Start Game</div>
	<div class='move'>Moves: <span class="c_move">0</span></div>
</div>
<br>
<br>
  <div class="room" align="center"></div>
<div class=board>
<p class="greet">Voila</p>
<p class="scr">Your Score</p>
<p class='scr_time'>Time : <span class='scr_min'>00</span>:<span class='scr_sec'>00</span> </p>
<p class = 'scr_move'>Moves :<span class='scr_moves'>  00</span></p>
<button type="button" class='again'> Again </button>
<p class="me">Developed by Mayur Birle</p>
</div>
<br><br>
<div class='me' align = "center"> Developed by Mayur Birle</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Courgette');
body {
	margin: 0 auto;
	font-family: 'Courgette', cursive;
}

.head {
	width: 100%;
	text-align: center;
	margin-top: 25px;
	font-size: 30px;
}

.head .time {
	float: left;
	width: 200px;
	text-weight: 650;
}

.head .start {
	display: inline-block;
	margin: 0 auto;
	margin-top: -20px;
	background: #7b7c7d;
	background-image: linear-gradient(to bottom, #7b7c7d, #242424);
	border-radius: 10px;
	color: #ffffff;
	font-size: 22px;
	padding: 20px 20px 20px 20px;
	text-decoration: none;
	text-weight: 600;
	cursor: pointer;
}

.head .move {
	float: right;
	width: 200px;
	text-weight: 650;
}

.room .card {
	display: inline-flex;
	width: 145px;
	height: 145px;
	position: relative;
	margin: 5px;
	transition: .40s;
	-webkit-transform-style: preserve-3d;
}
.room .card .face {
	width: 100%;
	height: 100%;
	position: absolute;
	-webkit-backface-visibility: hidden;
	z-index: 2;
}
.room .card .front {
	position: absolute;
	background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-1/profile/profile-512.jpg);
	background-repeat: no-repeat;
	background-size: 100%;
	z-index: 1;
}
.room .card .back {
	transform: rotateY(-180deg);
	position: absolute;
	background-repeat: no-repeat;
	background-size: 100%;
}

.flip, .fliped {
	transform: rotateY(180deg);
	transition: .40s;
}

.board {
	position: relative;
	width: 400px;
	top: -425px;
	height: 300px;
	border: 15px inset teal;
	border-radius: 20px;
	margin: 0 auto;
	text-align: center;
	background: #fff;
	color: #4d4ba3;
	box-shadow: 0px 0px 50px 0px rgba(50, 50, 50, 0.82);
}

.board .greet {
	font-size: 45px;
	margin: 10px;
	font-weight: 700;
}

.board .scr {
	font-size: 27px;
	margin: 10px;
	font-weight: 500;
}

.board .scr_time {
	display: inline-flex;
	font-size: 27px;
	margin: 10px;
	font-weight: 600;
}

.board .scr_move {
	display: inline-flex;
	font-size: 27px;
	margin: 10px;
	font-weight: 600;
}

.board .again {
	display: block;
	margin: 0 auto;
	margin-top: 10px;
	background: #2cbda5;
	background-image: linear-gradient(to bottom, #2cbda5, #123e59);
	border-radius: 15px;
	font-family: Arial;
	color: #ffffff;
	font-size: 25px;
	padding: 10px 20px 10px 20px;
	text-decoration: none;
}

.board .again:hover {
	background: #38c5de;
	background-image: linear-gradient(to bottom, #38c5de, #325063);
	text-decoration: none;
}

.me {
	font-size: 20px;
	margin-top: 20px;
	font-weight: 600;
}


@media only screen and (max-width: 890px) {
	.room .card {
		width: 95px;
		height: 95px;
	}

	.board {
		top: -385px;
	}
}
@media only screen and (max-width: 690px) {
	.room .card {
		width: 65px;
		height: 65px;
	}

	.board {
		width: 300px;
		top: -325px;
	}
}
@media only screen and (max-width: 400px) {
	.room .card {
		width: 40px;
		height: 40px;
	}

	.board {
		width: 300px;
		top: -125px;
	}
}

@media only screen and (max-width: 290px){
	.room .card {
		width: 25px;
		height: 25px;
	}
	
	.board {
		width: 300px;
		top: -90px;
	}
}


              
            
!

JS

              
                $(document).ready(function(){

 var img = [
'https://octodex.github.com/images/steroidtocat.png',
'https://octodex.github.com/images/megacat-2.png',
'https://octodex.github.com/images/dodgetocat_v2.png',
'https://octodex.github.com/images/mcefeeline.jpg',
'https://octodex.github.com/images/ironcat.jpg',
'https://octodex.github.com/images/gracehoppertocat.jpg',
'https://octodex.github.com/images/spidertocat.png',
'https://octodex.github.com/images/octocat-de-los-muertos.jpg',
'https://octodex.github.com/images/saritocat.png',
'https://octodex.github.com/images/plumber.jpg',
'https://octodex.github.com/images/linktocat.jpg',
'https://octodex.github.com/images/kimonotocat.png'	
]	

var	 total = 0,
	 move = 0,
	 count = 1,
	 first_card=null,
  	 secn_card=null ;

var stop_fa = false ,
	stop_fc = true,
 	stop_time = true;


var $card = $('.card'),
	$board = $('.board'),
	$start = $('.start'),
	$again = $('.again') ;


//4*6 card group;
var card_id=0 
 for(i=0; i<4; i++){
	for(j=0; j<6; j++){
		$('.room').append('	<div class="card" data-id="'+card_id+'"><div class="front face"></div><div  data-bid="0" class="back face" ></div></div>')
		card_id++;
		}
		$('.room').append('<br>')
	}




$start.click(function(){
	total = 0;
	stop_fa = true;
	stop_fc = false;
	stop_time = false;
	$('.card').removeClass('flip');
	$start.hide();
	randomIMG();
})

$again.click(function(){
	stop_fa = false;
	stop_fc = true;
	$start.show();
	$board.hide();
	$('.card').removeClass('fliped');
	randomIMG();
	flip_auto();
	flip_auto();
})

$board.hide();
randomIMG();
flip_auto();
flip_auto();
flip_auto();
flip_click();

// $('.card').addClass('fliped');

function randomIMG(){
	
	var c_array = [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12];
	var c_length = c_array.length;
	var $card = $('.card');
	

	$card.each(function(){
		var r_id = Math.floor(Math.random() * (c_length - 1));	// Get Random Number 
		
		
		var temp = c_array[r_id];							    //Swaping
		c_array[r_id]= c_array[c_length - 1];
		c_array[c_length - 1] = temp;


		c_length--												// decrement c_length by 1
		
		$(this).find('.back').css({								// Set css
			'background-image' : 'url('+img[temp-1]+')',
			'background-repeat' : 'no-repeat',
			'background-size': '100%'
		})

		$(this).find('.back').attr('data-bid',temp)		// Set data attribute
	})

	return 0;
}





function flip_click(){
	 total = 0;  
	 move = 0;
	 count = 1;
	 var i =0
	 first_card=null;
  	 secn_card=null ;
	var $card = $('.card');
	


	$card.find('.front').click(function(){

		if(stop_fc == true){
			return 0;
		}
   	

	$(this).parent('.card').toggleClass('flip');
	move++;
	$('.c_move').html(move);

	if(count == 1){
		first_card = $(this).parent('.card').find('.back').attr('data-bid');
	}
	else if(count == 2){
		secn_card = $(this).parent('.card').find('.back').attr('data-bid');
	}

	
	if(first_card == secn_card){
		
		$('[data-bid="'+first_card+'"]').parent('.card').addClass('fliped')
		total++;
		if (total == 12) {

			stop_time = true;
			

      		var sec_f = pad(++sec%60) , 
    		   min_f = pad(parseInt(sec/60,10)) ;
		stop_fc = reset(move,sec_f,min_f);
		stop_fc = true;
		move = 0;
		}

	}
	if(stop_fc){
		return
	}
count++
		if(count>2){
			console.log(first_card,secn_card)
			first_card=null;
			secn_card=null;
			count = 1;
		setTimeout(function(){
			$card.removeClass('flip');
			
		},400)
	}		
	});


	var sec = 0;
function pad ( val ) { return val > 9 ? val : "0" + val; }
setInterval( function(){
	if(stop_time){
    sec=0
		return
	}
    $(".sec").html(pad(++sec%60));
    $(".min").html(pad(parseInt(sec/60,10)));
}, 1000);


}


function flip_auto(time){	

  setTimeout( function(){
  	if(stop_fa){
	return ;
	}

	var r_ran = randomNum(1,24)
	$('[data-id="'+r_ran+'"]').toggleClass('flip')

	var newTime = randomNum(500,1000);	
	flip_auto(newTime)
  }, time)
}

 function randomNum( min, max ) {
    return Math.floor(Math.random() * ((max - min)+1) + min);
  }



function reset(move,sec,min) {
$board.show()
$board.find('.scr_moves').html(move);
$board.find('.scr_sec').html(sec);
$board.find('.scr_min').html(min);
return true;
}





});
              
            
!
999px

Console