css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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="main">
	
	<div id="circle-cont">
		
	<div id="green" class="circle-piece" onclick="pieceClick(this)"></div>
	<div id="red" class="circle-piece" onclick="pieceClick(this)"></div>
	<br>
	<div id="yellow" class="circle-piece" onclick="pieceClick(this)"></div>
	<div id="blue" class="circle-piece" onclick="pieceClick(this)"></div>
		
	</div>
	
	<center>
		<div id="center-piece">
<h1 class="title" style="color:#32CD32;">S</h1><h1 class="title" style="color:#DC143C;">I</h1><h1 class="title" style="color:#d4b100;">M</h1><h1 class="title" style="color:#4169E1;">O</h1><h1 class="title" style="color:#32CD32;">N</h1><h4 id="copy">&reg;</h4>
			<div id="count-box"></div>
			<div id="strict-check"></div>
			<button id="start" class="opt-btn" onclick="gameStart()"></button>
			<button id="reset" class="opt-btn" onclick="reset()"></button>
			<button id="strict" class="opt-btn" onclick="toggleStrict()"></button>
		<div></div>
			<h5 class="btn-label" for="start">START</h5>
			<h5 class="btn-label" for="reset">RESET</h5>
			<h5 class="btn-label" for="strict">STRICT</h5>
			
		</div>
	</center>
	
	
</div>
            
          
!
            
              html, body{
	background-image:url('http://res.cloudinary.com/dwrytmxwf/image/upload/v1525190128/art-back_zuu6oo.png');
	font-family: 'Press Start 2P', cursive;
	
}

.circle-piece{
	margin:0;
	padding:0;
	height:15em;
	width:15em;
	border: .5em solid #714A77;
	display:inline-block;
	box-shadow: 0px 0px 10px 2px #714A77;
}

#copy{
	font-size:1.5em;
	margin-top:1.5em;
	display:inline-block;
	text-shadow:1px 1px #333;	
	
}

#circle-cont{
	position:absolute;
	left:-webkit-calc(50% - 16em);
	left:-moz-calc(50% - 16em);
	left:calc(50% - 16em);
	transition:transform 2s;
	transition-timing-function:ease-in-out;
}

#center-piece{
	height:20em;
	width:20em;
	position:relative;
	top:5.20em;
	border:solid #714A77 1em;
	border-radius:50%;
	background:#DA81AD;
}

#green{
	float:left;
	padding:0;
	margin:0;
	border-radius: 16em 0 0 0;
	background:#32CD32;
}

#red{
	float:left;
	padding:0;
	margin:0;
	border-radius: 0 16em 0 0;
	background:#DC143C;
}

#yellow{
	float:left;
	margin:0;
	border-radius: 0 0 0 16em;
	background:#d4b100;
}

#blue{
	float:left;
	margin:0;
	border-radius: 0 0 16em 0;
	background:#4169E1;
}



#start{
	background:#32CD32;
	
}

#reset{
	background:#d4b100;
}

#strict{
	background:#DC143C;
}

#strict-check{
	height:.5em;
	width:.5em;
	background:#1E141D;
	margin-left:6em;
	border-radius:50%;
	border-style:outset;
	margin-top:.5em;
	margin-bottom:.5em;
	transition:background .2s;
}

.title{
	font-size:3em;
	margin-top:1.5em;
	display:inline-block;
	text-shadow:1px 1px #333;
}

#count-box{
	height:1.3em;
	width:12em;
	background:#1E141D;
	margin-top:1em;
	border-radius:2px;
	border-style:outset;
	color:#F7A35B;
	font-size:1em;
	text-align:center;
}

.btn-label{
	font-size:.4em;
	display:inline-block;
	color:#302138;
}

.opt-btn{
	height:1em;
	width:1em;
	border-radius:50%;
	background:#1E141D;
  margin-top:0;
	font-size:2em;
	box-shadow: 0 .1em #999;
	transition:transform .5s;
}

.opt-btn:focus{
	outline:none;
}

.opt-btn:hover{
	box-shadow: 0 .05em #666;
  transform: translateY(.05em);
	
}
            
          
!
            
              var simonArray ;
var playerSelect = "";
var count = 0;
var gameCount = 0;
var interval1 = null;
var interval2 = null;
var strict = false;


var soundRed = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3");
var soundBlue = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3");
var soundGreen = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3");
var soundYellow = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");
var soundError = new Audio("http://res.cloudinary.com/dwrytmxwf/video/upload/v1525187111/error_f09yec.mp3");

var soundWinner = new Audio('http://res.cloudinary.com/dwrytmxwf/video/upload/v1525193826/winner_cciqba.wav');

var soundGameOver = new Audio("http://res.cloudinary.com/dwrytmxwf/video/upload/v1525203504/game-over_ius00t.wav");

function pieceClick(event){
	
	
	
	playerSelect = event.id;
	highlight(event.id);

	
	
	if(playerSelect === simonArray[count]) {
		
		playSound(event.id);
		count++;
		
		if(count == simonArray.length){
			gameCount = simonArray.length;
			$("#count-box").html(count);
			if(gameCount == 20) {$("#count-box").html("Winner!");soundWinner.load();soundWinner.play();
													$("#circle-cont").css("transform","rotate(1080deg)");
													return;}
			count = 0;
			randomColor();
			var intVal1 = 0;
			$(".circle-piece").css("pointer-events","none");
			interval1 = setInterval(function(){
				if(intVal1 == simonArray.length){
					$(".circle-piece").css("pointer-events","auto");
					clearInterval(interval1);
				}
				highlight(simonArray[intVal1]);
				playSound(simonArray[intVal1]);
				intVal1++;
			}, 800);
			}
		
		}
		else{
			soundError.load();
			soundError.play();
			if(strict){
				soundGameOver.load();
				soundGameOver.play();
				$("#count-box").html("Game Over");
				gameStart();
				return;
			}
			count = 0;
			var intVal2 = 0;
			$(".circle-piece").css("pointer-events","none");
			interval2 = setInterval(function(){
				if(intVal2 == simonArray.length){
					$(".circle-piece").css("pointer-events","auto");
					clearInterval(interval2);}
				highlight(simonArray[intVal2]);
				playSound(simonArray[intVal2]);
				intVal2++;
			}, 800);
			
		}
	}
	


function gameStart(){
	simonArray = [];
	count = 0;
	gameCount = 0;
	playerSelect = "";
		$("#circle-cont").css("transform","none");
	var r = randomColor();
	highlight(r);
	playSound(r);
}

function toggleStrict(){
	if(strict==false){
		strict = true;
		$("#strict-check").css("background","#DC143C");
	}
	else{
		strict = false;
		$("#strict-check").css("background","#1E141D");
	}

}

function reset(){
	simonArray = [];
	count = 0;
	gameCount = 0;
	playerSelect = "";
	$("#count-box").html("RESET");
	$("#circle-cont").css("transform","none");
	clearInterval(interval1);
	clearInterval(interval2);
}

function randomColor(){
	
	var rand = Math.floor(Math.random() * 4);
	
	if(rand == 0) {simonArray.push("green"); 
								 return "green";
								}
	if(rand == 1) {simonArray.push("red");
								 return "red";
								}
	if(rand == 2) {simonArray.push("yellow"); 
								 return "yellow";
								}
	if(rand == 3)	{simonArray.push("blue"); 
								 return "blue";
								}

}

function highlight(color){
	
	
	if(color == "red"){
		 $("#red").css("background","#ff1540");
								 var s = setTimeout(function(){
									  $("#red").css("background","#DC143C");
									 
							
								 },700);
		
	}
		if(color == "green"){
			 $("#green").css("background","#43ff40");
							var s =	setTimeout(function(){
									  $("#green").css("background","#32CD32");
									 	
								
								 },700);
		
		}
			if(color == "yellow"){
				$("#yellow").css("background","#ffd500");
								 var s = setTimeout(function(){
									  $("#yellow").css("background","#d4b100");
									 console.log("highlighted");
								
								 },700);
				
			}
				if(color == "blue"){
					 $("#blue").css("background","#4b78ff");
								var s = setTimeout(function(){
									  $("#blue").css("background","#4169E1");
									 console.log("highlighted");
								
								 },700);
				
				}

}

function playSound(color){
	
	if(color == "red") {
		soundRed.load();
		soundRed.play();
	}
	
	if(color == "blue") {
		soundBlue.load();
		soundBlue.play();
	}
	
	if(color == "yellow") {
		soundYellow.load();
		soundYellow.play();
	}
	
	if(color == "green") {
		soundGreen.load();
	  soundGreen.play();
	}
	
}
            
          
!
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.
Loading ..................

Console