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.

            
                <div id="wrap" class="container-fluid pull-center">
<div class="hero text-center">
<h1>Do <em>What</em> with the Coconut?</h1>
<h3>A Simon Says &mdash; 
  Style Game</h3>
   <span id="msg2"></span><br/>
</div><!-- close hero -->
<div id="columnContent" class="pull-center text-center">
  <div id="board">

   <div class="row kiwipine row-fluid">
   <div id = "0" class = "space coco pull-left"></div>
   <div id = "1" class = "space coco pull-right"></div>
   </div>

    <div class="row mangopassion row-fluid">
   <div id = "2" class = "space coco pull-left"></div>
   <div id = "3" class = "space coco pull-right"></div>
   </div>
   
   </div><!-- board -->
   
   <div id="control" class="pull-right">
   <span id="msg"></span><br/>
   <span id="msg1"></span>
<div id="round"> Round: <span class="roundNum"></span></div>
<div id="strict"> Strict Mode: <span class="strictMode">OFF</span><br/>
<button id="strictOn" class="btn btn-success" value="strictOn"> On </button>
<button id="strictOff" class="btn btn-warning" value="strictOff"> Off </button></div>
<button id="start" class="btn" value="start"> Start </button>
<button id="reset" class="btn" value="reset"> Reset </button>
</div>
</div><!-- columnContent -->
<div class="skiwi">
        <audio preload="auto" id="kiwisnd">
          <source src="https://konikodes.com/fcc/simon/img/kiwi.mp3" type="audio/mgeg" autostart="false" />
          <source src="https://konikodes.com/fcc/simon/img/kiwi.ogg" type="audio/ogg" autostart="false" />
        </audio>
      </div>

<div class="spine">
        <audio preload="auto" id="pinesnd">
          <source src="https://konikodes.com/fcc/simon/img/pine.mp3" type="audio/mgeg" autostart="false" />
          <source src="https://konikodes.com/fcc/simon/img/pine.ogg" type="audio/ogg" autostart="false" />
        </audio>
      </div>
	  
<div class="smango">
        <audio preload="auto" id="mangosnd">
          <source src="https://konikodes.com/fcc/simon/img/mango.mp3" type="audio/mgeg" autostart="false" />
          <source src="https://konikodes.com/fcc/simon/img/mango.ogg" type="audio/ogg" autostart="false" />
        </audio>
      </div>	
	    
<div class="spassion">
        <audio preload="auto" id="passionsnd">
          <source src="https://konikodes.com/fcc/simon/img/passion.mp3" type="audio/mgeg" autostart="false" />
          <source src="https://konikodes.com/fcc/simon/img/passion.ogg" type="audio/ogg" autostart="false" />
        </audio>
      </div>	 

<div class="swrong">
        <audio preload="auto" id="wrongsnd">
          <source src="https://konikodes.com/fcc/simon/img/wrong.mp3" type="audio/mgeg" autostart="false" />
          <source src="https://konikodes.com/fcc/simon/img/wrong.ogg" type="audio/ogg" autostart="false" />
        </audio>
      </div>	
	
	<div class="slost">
        <audio preload="auto" id="lostsnd">
          <source src="https://konikodes.com/fcc/simon/img/lost.mp3" type="audio/mgeg" autostart="false" />
          <source src="https://konikodes.com/fcc/simon/img/lost.ogg" type="audio/ogg" autostart="false" />
        </audio>
      </div>	  
	  
	<div class="swinner">
        <audio preload="auto" id="winnersnd">
          <source src="https://konikodes.com/fcc/simon/img/winner.mp3" type="audio/mgeg" autostart="false" />
          <source src="https://konikodes.com/fcc/simon/img/winner.ogg" type="audio/ogg" autostart="false" />
        </audio>
      </div>	  
</div> <!-- wrap -->
            
          
!
            
              body{
    width:100%;
	height:100%;
	margin:0;
	padding:0;
	border:0;
	font-family:Georgia, serif;	
	color:#fbf2ea;	
	background:url(https://konikodes.com/fcc/simon/img/background.jpg) no-repeat center center;
	position: fixed;
	background-attachment: fixed;
    background-size:cover;
	-webkit-background-size: cover;
	-o-background-size: cover;

}
#wrap {
   display: inline-block;
   width:100%;
   height:100%;
   margin:0;
   padding:0;
   overflow:auto;
}
.hero{
    margin:0 auto;
	width:100%;
	color: #796309;
	font-weight:bold;
	padding:0;
}
h3{
   font-size: 1.2em;
   line-height: 1.3em;
   margin:0;
   padding:0;
}

.kiwipine{
   margin:4.1em 0 0 5.5em;
}

.kiwi, .pine{
   cursor: pointer;
}
.mangopassion{
   margin:0 0 0 5.5em;
}

.mango, .passion {
   cursor: pointer;

}

#columnContent{
   width: 650px;
   height: 420px;
   margin: 2em auto;
   padding: 0;
} 

#board{ 
   display: inline-block;
   margin:1em 0;
   padding:0;
   width:320px;
   height:350px;
   background-repeat: no-repeat;
   background-color: transparent;
   bottom:0;
}

#board > .row {
   height: 90px;
   width: 60%;

   padding:0;
}

.space{
   width:85px;
   height:100%;
}

.cboard {
   background:url(https://konikodes.com/fcc/simon/img/cocoboard.png) 100% 100% no-repeat;
   background-color: transparent;
   vertical-align: baseline;
}

.cwin{
    background: url(https://konikodes.com/fcc/simon/img/cocomix.png) 80% 80% no-repeat;
    background-color: transparent;

	
}
.coco{
    background: url(https://konikodes.com/fcc/simon/img/coco.png) 100% 100% no-repeat;
    background-color: transparent;
}
.ckiwi {
    background: url(https://konikodes.com/fcc/simon/img/cocokiwi.png) 100% 100% no-repeat;
    background-color: transparent;

}
.cpine {
    background: url(https://konikodes.com/fcc/simon/img/cocopine.png) 80% 80% no-repeat;
    background-color: transparent;
}
.cmango {
    background: url(https://konikodes.com/fcc/simon/img/cocomango.png) 80% 80% no-repeat;
    background-color: transparent;
}
.cpassion {
    background: url(https://konikodes.com/fcc/simon/img/cocopassion.png) 80% 80% no-repeat;
    background-color: transparent;
}

#start, #reset{
    width:95%;
	background-color: #775726;
	border-radius: 4px;
	color: #fff;
	line-height: 1.5em;
	margin:1.5em auto;
    padding:1em;
	font-size:1.2em;
	cursor: pointer;
}

#round, #strict {
    background: transparent;
	border: 2px solid #775726;
	border-radius: 4px;
	color: #775726;
	line-height: 1.5em;
	margin:1.5em auto;
    padding:1em;
	font-size:1.2em;
	cursor: pointer;
}
#msg {
	color: #775726;
	margin:1.5em auto;
    padding:1em;
	font-size:1.4em;
	font-weight: bold;
}
#msg1 {
	color: #775726;
	margin:1.5em auto;
    padding:1em;
	font-size:1.4em;
	font-weight: bold;
}
#msg2 {
	color: #775726;
	margin:0 auto;
	padding: 0;
	font-size:1.6em;
	font-weight: bold;
	font-style: italic;
}	

.roundNum{
	color: #775726;
	font-size:1.5em;
	font-weight: bold;
}
.strictMode{
	border-radius: 4px;
	color: #775726;
	line-height: 1.5em;
	margin:1.5em auto;
    padding:.75em;
	font-size:1.3em;
	font-weight: bold;
	cursor: pointer;
}
@media only screen and (max-width:700px){
.hero{
	width:90%;
	padding:1em;
}
h3{
   font-size: 1.1em;
   line-height: 1.2em;
}

#columnContent{
   width: 90%;
   margin: 0;
   padding: 0;
} 
#board{ 
   display: inline-block;
   margin:1em 0 0 1em;
   padding:0;
   width:320px;
   height:300px;
}

#board > .row {
   padding:0 0 0 2.5em;
   margin: 0 auto;
   height: 90px;
   width: 80%;
}
.space{
   width:85px;
   height:100%;
}


#start, #reset{
    width:80%;
	line-height: 1.3em;
	margin:0 auto;
    padding:.5em;
}

#round, #strict {
    width:80%;
	line-height: 1.3em;
	margin:.5em auto;
    padding:.5em;
	cursor: pointer;
}
#msg {
	margin:0 auto;
    padding:.5em;
	font-size:1.2em;
}
#msg1 {
	margin:0 auto;
    padding:.5em;
	font-size:1.2em;
}
#msg2 {
	margin:0 auto;
    padding:0;
	font-size:1.2em;
}	

.roundNum{
	font-size:1.3em;
}
.strictMode{
	border-radius: 4px;
	color: #775726;
	line-height: 1.2em;
	margin:0 auto;
    padding:.5em;
	font-size:1.1em;
}
}
            
          
!
            
              $(document).ready(function () {
'use strict';

var fruit = ["kiwi", "pine", "mango", "passion"],
	  simonseq = [], // random number for simon to use
      playrseq = [], // numbers clicked by user
      i = 0,
      round = 0,
	  maxRound = 20,
      strict = false,
	  error = false,
	  delayErr = false,
	  waiter,
	  waiting,
      animationStopped = true,
      startTime;
$("#board").addClass("cboard");	  
$("#strictOff").hide();
$("#reset").hide();
$("#msg").text("  ");   
 $("#msg1").text("Dance for " + maxRound + " Rounds");   
 
$("#strictOn").on("click", function(){
    $(this).hide();
    $("#strictOff").show();
    $(".strictMode").text("ON");
    strict = true;
});

$("#strictOff").on("click", function(){
    $(this).hide();
    $("#strictOn").show();
    $(".strictMode").text("OFF");
    strict = false;
});


$("#start").on("click", function(){
    $(this).hide();
    $("#reset").show();
	$("#strictOff").off("click");
	$("#strictOn").off("click");
	$("#msg").empty(); 
    $("#msg1").empty();
    round = 0;
	for (i=0; i < 20; i++) {
   simonseq[i] = Math.floor(Math.random() * 4);

	}
    console.log("Random List is " + simonseq);
     newRound();
	
});

$("#reset").on("click", function(){
     resetGame();
});

function resetGame(){
	  simonseq = [], // random number for simon to use
      playrseq = [], // numbers clicked by user
      round = 0,
	  maxRound = maxRound,
      strict = false,
	  error = false;
	$(".roundNum").text(" ");
	$("#strictOff").hide();
    $("#strictOn").show();
    $(".strictMode").text("OFF");
	$("#board").removeClass("cwin");
	$("#board").addClass("cboard");	
			  for (i = 0; i < 5; i++){
		   $('*[id="' + i + '"]').addClass("coco");	
			  }
    $("#msg").empty();
$("#msg1").text("Dance for " + maxRound + " Rounds"); 
	$("#msg2").empty(); 
	$("#reset").hide();
    $("#start").show();
}	

function newRound() {
    $("#msg").empty();
	$("#msg1").empty();
   round ++;
  $(".roundNum").text(round);
  simonMove();
}
 function simonMove(){
    $("#0,#1,#2,#3").css("pointer-events", "none");
	 var i = 0;
	var classAdded;
	var ind;
	var hilite = setInterval(timing, 450);
	 
      function timing(){
        var step=Math.floor(i/4);
          animationStopped=false;


	    if (i%4===1 && i< round*4){
            if (simonseq[step] === 0){
				console.log("Button pressed "  + simonseq[step] + " at Round " + round);		
               $('*[id="' +0+ '"]').addClass("ckiwi");
                 kiwisnd.load();
                 kiwisnd.play();
                 classAdded = "ckiwi";
				 ind = 0;
             } else if (simonseq[step] === 1){
				console.log("Button pressed "  + simonseq[step] + " at Round " + round);		
                 $('*[id="' +1+ '"]').addClass("cpine");
                 pinesnd.load();
                 pinesnd.play();
                 classAdded = "cpine";
				 ind = 1;
             } else if (simonseq[step] === 2){
				console.log("Button pressed "  + simonseq[step] + " at Round " + round);		
               $('*[id="' +2+ '"]').addClass("cmango");
                 mangosnd.load();
                 mangosnd.play();
                 classAdded = "cmango";
				 ind = 2;
             } else if (simonseq[step] === 3){
 				console.log("Button pressed "  + simonseq[step] + " at Round " + round);		
			     $('*[id="' +3+ '"]').addClass("cpassion");
                 passionsnd.load(); 
                 passionsnd.play();
                 classAdded = "cpassion";
				 ind = 3;
           }
        } else if (i%4===2 && i< round*4){ 
		   if (ind === 0){
            $('*[id="' +ind+ '"]').removeClass("ckiwi");
		}
		  else if (ind === 1){
            $('*[id="' +ind+ '"]').removeClass("cpine");
		}
		else if (ind === 2){
            $('*[id="' +ind+ '"]').removeClass("cmango");
		}	
		else if (ind === 3){
            $('*[id="' +ind+ '"]').removeClass("cpassion");
		}	
		//console.log("clearing id " + ind + " of " + classAdded);
	    //round++;

        } else if (i===round*4){
		console.log("Clearing Interval and going to Player Move");
            clearInterval(hilite);
			  $("#msg1").text("Your Turn");
			 $("#0,#1,#2,#3").css("pointer-events", "auto");
       playrMove();
        }
        i++;
	
    }
}

function playrMove(){
   console.log("playr called");
     playrseq = [];
		  for (i = 0; i < 5; i++){
		   $('*[id="' +i+ '"]').on("click");
		  }

}
  
  //player listener
  $("#0").mousedown(function() {

	 if (! animationStopped){
         $('*[id="' + 0 + '"]').addClass("ckiwi");
         kiwisnd.load();
         kiwisnd.play();
         playrseq.push(0);
         //console.log("Player played " +playrseq + " for Round " + round);
         //console.log("pushed player length is " + playrseq.length);
         //console.log("Player list is " + playrseq);
          console.log("Button pressed " + 0 );
     }
	 });
	  $("#0").mouseup(function() { 
	 if (! animationStopped){
         $('*[id="' + 0 + '"]').removeClass("ckiwi");	 
         checkPlay();
     }
});

  $("#1").mousedown(function() {
	 if (! animationStopped){
         $('*[id="' + 1 + '"]').addClass("cpine");
         pinesnd.load();
         pinesnd.play();
         playrseq.push(1);
         //console.log("Player played " +playrseq + " for Round " + round);
         //console.log("pushed player length is " + playrseq.length);
         //console.log("Player list is " + playrseq);
          console.log("Button pressed " + 1 );
     }
     });		 
	  $("#1").mouseup(function() {
	 if (! animationStopped){
         $('*[id="' + 1 + '"]').removeClass("cpine");	 
        checkPlay();
     }
});

  $("#2").mousedown(function() {
	 if (! animationStopped){
         $('*[id="' + 2 + '"]').addClass("cmango");
         mangosnd.load();
         mangosnd.play();
         playrseq.push(2);
         //console.log("Player played " +playrseq + " for Round " + round);
         //console.log("pushed player length is " + playrseq.length);
         //console.log("Player list is " + playrseq);
          console.log("Button pressed " + 2);
     }
     });		 
	  $("#2").mouseup(function() {
	 if (! animationStopped){
         $('*[id="' + 2 + '"]').removeClass("cmango");	 
	   checkPlay();
     }
});

  $("#3").mousedown(function() {
	if (! animationStopped){
         $('*[id="' + 3 + '"]').addClass("cpassion");
         passionsnd.load();
         passionsnd.play();
         playrseq.push(3);
         //console.log("Player played " +playrseq + " for Round " + round);
         //console.log("pushed player length is " + playrseq.length);
         //console.log("Player list is " + playrseq);
          console.log("Button pressed " + 3);
    }
	});	 
  $("#3").mouseup(function() {
	 if (! animationStopped){
         $('*[id="' + 3 + '"]').removeClass("cpassion");	 
        checkPlay();
     }
	});


 function checkPlay(){		
//check playr sequence
 		$("#msg").empty();
		$("#msg1").empty();
   if (playrseq[playrseq.length-1]===simonseq[playrseq.length-1]){
    if (playrseq.length===round){
	// if playr and simon match then check for winner
	    console.log("correct round " +round);
         clearInterval(waiting);
		 
        if(maxRound === round) {

		$("#msg2").text("Congratulations! You Won!");
        $("#board").addClass("cwin");
		$("#board").removeClass("cboard");
		  winnersnd.load();
          winnersnd.play();		
	  for (i = 0; i < 5; i++){
		   $('*[id="' + i + '"]').removeClass("coco");	
			}
		 setTimeout (function(){
		resetGame();   
			  }, 8000);
      } else {
	  setTimeout (function(){
            playrseq = [];
			round++;
			$(".roundNum").text(round);
			$("#msg").empty();
			$("#msg1").empty();
            simonMove();
		}, 750);
          }
       }
	   
    }else {
      // Otherwise it is an Error
	  if (!strict){
	  setTimeout (function(){
	  console.log("incorrect "+round);
	  wrongsnd.play();  
	  $("#msg").text("You Missed a Step!");
	  $("#msg1").text("Try Again");
		round = round;
       $("#roundNum").text(round);
      clearInterval(waiting);
        playrseq = []; 
        simonMove();		 
		}, 1000);	 
}

 else if(strict) {
		$("#msg").empty(); 
        $("#msg1").empty();
		lostsnd.load();
		lostsnd.play();
		setTimeout (function(){
		$("#msg").text("Error in Strict Mode");		
		$("#msg1").text("Start Game Over!");
		    }, 1000);

	//	console.clear();
			$("#msg").empty(); 
        $("#msg1").empty();
			animationStopped=false;
	        resetGame();
    } 
 }
 }
  });

            
          
!
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