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

              
                <h3>Arrange the boxes in order with the help of blank box, in time ;)</h3>
<div class="mainBox">
    	<div class="box" id="id_0"></div>
        <div class="box" id="id_1"></div>
        <div class="box" id="id_2"></div>
        <div class="box" id="id_3"></div>
        <div class="box" id="id_4"></div>
        <div class="box" id="id_5"></div>
        <div class="box" id="id_6"></div>
        <div class="box" id="id_7"></div>
        <div class="box" id="id_8"></div>
        <div class="box" id="id_9"></div>
        <div class="box" id="id_10"></div>
        <div class="box" id="id_11"></div>
        <div class="box" id="id_12"></div>
        <div class="box" id="id_13"></div>
        <div class="box" id="id_14"></div>
        <div class="activeBox" id="id_15"></div>
        	
    </div>
<div id="timeLeft">
  <div>
    <span class="minutes"></span>
    <div class="smalltext">Minutes</div>
    <h5>Time</h5>
  </div>
  <div>
    <span class="seconds"></span>
    <div class="smalltext">Seconds</div>
    <h5>Left</h5>
  </div>
  <div id="demoPic"></div>
</div>

              
            
!

CSS

              
                body {
  background: none repeat scroll 0 0 #7FCA74;
  width: 100%;
  font-family: "Arial Narrow", Arial;
}
.mainBox {
  background: none repeat scroll 0 0 #EEEEEE;
  height: 398px;
  width: 397px;
  margin: 0 auto;
  padding-left: 3px;
  padding-top: 3px;
  border: 1px solid #dddddd;
  -webkit-box-shadow: 5px 5px 10px 3px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: 5px 5px 10px 3px rgba(0, 0, 0, 0.75);
  box-shadow: 5px 5px 10px 3px rgba(0, 0, 0, 0.75);
  background: none repeat scroll 0 0 #EEEEEE;
    height: 499px;
    width: 500px;
    margin: 0 auto;
    padding-left: 3px;
    padding-top: 3px;
    border: 1px solid #dddddd;
}

.box {
  background-image: url(https://s3-ap-southeast-1.amazonaws.com/dearsaiftest/cats.jpg) !important;
    border-radius: 10px;
    border: 1px solid #72726E;
    float: left;
    font-family: arial, "Comic Sans MS", cursive;
    font-size: 57pt;
    height: 103px;
    margin-bottom: 2px;
    margin-left: 1px;
    margin-right: 1px;
    text-align: center;
    width: 120px;
    color: #34452C;
    padding-top: 17px;
}

.activeBox {
  background: #34452c;
  background-image: none;
    border-radius: 10px;
    border: 1px solid #72726E;
    float: left;
    height: 120px;
    width: 120px;
    margin: 1px;
}

.clickable {
  background: #ccc;
  border-radius: 10px;
  border: 1px solid #72726E;
  cursor: pointer;
}

.clickable:hover {
  background: #34452c;
  color: #FFF;
}

.note {
  background-color: #C3D4BB;
  font-family: Arial, Helvetica;
  font-size: 10pt;
  padding: 5px 5px 10px;
  text-align: center;
  width: 39%;
  font-weight: 100;
  font-size: 40px;
  margin: 40px 0px 20px;
}

#timeLeft{
	color: #fff;
	display: table;
	font-weight: 100;
	text-align: center;
	font-size: 30px;
  margin: 25px auto;
  
}

#timeLeft > div{
	padding: 10px;
	border-radius: 3px;
	background: #caf7c4;
  color: #000;
	display: table-cell;
  border: 1px solid #bbb;
}

#timeLeft div > span{
	padding: 15px;
	color: #fff;
	border-radius: 3px;
	background: #34452c;
	display: inline-block;
}

.smalltext{
	padding-top: 5px;
	font-size: 16px;
}
h3,h5{
  margin: 10px;
  color: #34452c;
  text-align: center;
}
#demoPic{
  margin-left: 10px !important;
  background-image: url(https://s3-ap-southeast-1.amazonaws.com/dearsaiftest/cats.jpg) !important;
  background-size: 155px !important;
    background-repeat: no-repeat !important;
  height: 150px;
  width: 155px; 
  padding: 0 !important;
}
              
            
!

JS

              
                var number = new Array();
var init_number = new Array();
putValue();
var active = 15;
init(active);
var deadline = new Date(Date.parse(new Date()) + 5 * 60 * 1000);
		//alert(init_number[0]);
		function init(idN) {
			idN = parseInt(idN)
			$('.clickable').removeClass('clickable');
			if(idN!=3 && idN!=7 && idN!=11)
			{
				click1 = idN+1;
				click1 = '#id_'+click1;
				$(click1).addClass('clickable');
			}
			if(idN!=4 && idN!=8 && idN!=12)
			{
				click2 = idN-1;
				click2 = '#id_'+click2;
				$(click2).addClass('clickable');
			}
			click3 = idN+4;
			click3 = '#id_'+click3;
			$(click3).addClass('clickable');
			click4 = idN-4;
			click4 = '#id_'+click4;
			$(click4).addClass('clickable');
			//alert(idN);
		}
		$(".mainBox").delegate(".clickable", "click", function(){ 
			var idNo = $(this).attr('id');
			idNo = idNo.split("_");
			active = toggle(idNo[1],active,number);
			init(idNo[1]);
			result(number);
		});


		
		$('body').keyup(function(e){
			if(e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 39 || e.keyCode == 40)
			{
				
					if(e.keyCode == 37){
						
						if(active!=15 && active!=11 && active!=7 && active!=3)
							{
								active = active + 1;
								active = toggle(active,active-1,number);
								init(active);
							}
						}
					if(e.keyCode == 39){
						
						if(active!=12 && active!=8 && active!=4 && active!=0)
							{
								active = active - 1;
								active = toggle(active,active+1,number);
								init(active);
							}
						}
					if(e.keyCode == 38){
						if(active!=12 && active!=13 && active!=14 && active!=15)
							{
								active = active + 4;
								active = toggle(active,active-4,number);
								init(active);
							}
						}
					if(e.keyCode == 40){
						if(active!=0 && active!=1 && active!=2 && active!=3)
							{
								active = active - 4;
								active = toggle(active,active+4,number);
								init(active);
							}
						}
			
			result(number);
			}
			});

	
		function result(number){
				
				
				var number_init = [15];
				var x=0,y=0;
				for(i=0;i<=14;i++){
					number_init[i]=x+","+y;
					if(i!=3 && i!=7 && i!=11)
					{
						x = x - 125;
					}else{
						x=0;
						y= y - 125;
					}
				}
				if(number.length==16)
					 {
					 //number.splice(15, 1);//number.pop();
					number_init[15] = number[15];
					 }
				//alert(number);
				number1=number.toString();
				number_init1=number_init.toString();
				if(number1===number_init1)
				{
					alert("CONGRATULATIONS! You won. Start a New Game.");
					//location.reload();
          var deadline = new Date(Date.parse(new Date()) + 5 * 60 * 1000);
initializeClock('timeLeft', deadline);
      putValue();
      var active = 15;
      init(active);
				}
				
		}
		function toggle(ID,active,number){
				$('#id_'+ID+'').removeClass('box');
				$('.activeBox').addClass('box');
				var pos = number[ID].split(",");
				//$('.activeBox').css("background-image", "url(imgs/cats.jpg)");
				$('.activeBox').css("background-position", pos[0]+"px "+pos[1]+"px");
				$('.activeBox').removeClass('activeBox');
				$('#id_'+ID+'').addClass('activeBox');
				number[active]=number[ID];
				
				return ID;
				
				
		}
		
		function putValue(){
//var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
	function shuffle(o){ 
    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
    return o;
};

//var numbers = shuffle(numbers);
var x=0;
var y=0;


	for(i=0;i<=14;i++){
		
		//document.getElementById("id_"+i).innerHTML  = numbers[i];
		//$("#id_"+i).css("background-position", x+"px "+y+"px");
		init_number[i]=x+","+y;
    
		if(i!=3 && i!=7 && i!=11)
		{
			x = x - 125;
		}else{
			x=0;
			y= y - 125;
		}
	}
	number = shuffle(init_number);
	//num_y = shuffle(num_y);
	
	for(i=0;i<=14;i++){
		var pos = number[i].split(",");
 		//alert("Hi");
		//if(number[i]!="1,1")
			$("#id_"+i).css("background-position", pos[0]+"px "+pos[1]+"px");
	}
}
/*----------TIME--------*/
function getTimeRemaining(endtime) {
  var t = Date.parse(endtime) - Date.parse(new Date());
  var seconds = Math.floor((t / 1000) % 60);
  var minutes = Math.floor((t / 1000 / 60) % 60);
  return {
    'total': t,
    'minutes': minutes,
    'seconds': seconds
  };
}

function initializeClock(id, endtime) {
  var clock = document.getElementById(id);
  var minutesSpan = clock.querySelector('.minutes');
  var secondsSpan = clock.querySelector('.seconds');

  function updateClock() {
    var t = getTimeRemaining(endtime);
    minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
    secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);

    if (t.total <= 0) {
      clearInterval(timeinterval);
      alert("SORRY!!! You lost the game :( Please try again.");
      var deadline = new Date(Date.parse(new Date()) + 5 * 60 * 1000);
initializeClock('timeLeft', deadline);
      putValue();
      var active = 15;
      init(active);
    }
  }

  updateClock();
  var timeinterval = setInterval(updateClock, 1000);
}
initializeClock('timeLeft', deadline);
              
            
!
999px

Console