cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <div id="simon-frame">
			
			<div id="green-field" class="field">
			</div>
			<div id="red-field" class="field">
			</div>
			<div id="yellow-field" class="field">
			</div>
			<div id="blue-field" class="field">
			</div>
			<div id="simon-circle">
				<div id="title">Simon</div>
				<div id="count">
					<div id="count-numbers">- -</div>
				</div>
				<div class="menu-buttons" id="start">
				</div>
				<div class="menu-buttons" id="strict">
				</div>
				<div class="titles">Count</div>
				<div class="titles" id="title-start">Start</div>
				<div class="titles">Strict</div>
				<div id="strict-mode-led">
				</div>
				<div id="switch-div">
					<div class="switch-button-off">OFF</div>
					<label  class="switch"><input type="checkbox" id="dd" />    <div ></div>
					</label>
					<div class="switch-button-on">ON</div>
				</div>
			</div>
			<div id="wrong">WRONG</DIV>
			<div id="win">YOU WON</DIV>
		
	</div>
            
          
!
            
              html, body {
	background-color: black;
}

#simon-frame {
	border-radius: 50%;
	width:499px;
	height:499px;
	background-color:gray;
	margin-left:auto;
	margin-right: auto;
	margin-top:100px;
}

#green-field {
	background-color: green;
	width: 233px;
	height: 233px;
	float: left;
	border: solid 8px;
	border-color: #333333;
	-webkit-border-top-left-radius: 240px;
	-moz-border-radius-topleft: 240px;
	border-top-left-radius: 240px;
}

#red-field {
	background-color: red;
	width: 233px;
	height: 233px;
	float: left;
	border: solid 8px;
	border-color: #333333;
	-webkit-border-top-right-radius: 240px;
	-moz-border-radius-topright: 240px;
	border-top-right-radius: 240px;
}

#yellow-field {
	background-color: yellow;
	width: 233px;
	height: 233px;
	float: left;
	border: solid 8px;
	border-color: #333333;
	-webkit-border-bottom-left-radius: 240px;
	-moz-border-radius-bottomleft: 240px;
	border-bottom-left-radius: 240px;
}

#blue-field {
	background-color: blue;
	width: 233px;
	height: 233px;
	float: left;
	border: solid 8px;
	border-color: #333333;
	-webkit-border-bottom-right-radius: 240px;
	-moz-border-radius-bottomright: 240px;
	border-bottom-right-radius: 240px;
}

.field {
	cursor:pointer;
	
}

.field:active {
	background-color: white!important;

	
}




#simon-circle {
	position:absolute;
	border-radius: 50%;
	width:250px;
	height:250px;
	background-color:lightgrey;
	margin-left:100px;
	margin-right: 125px;
	margin-top:125px;
	border: solid 16px;
}

#title {
	font-size: 44px;
	font-family: 'Shrikhand', cursive;
	text-align: center;
	padding-top: 30px;
	
}

#count {
	height:40px;
	width:60px;
	background-color: #7b0303;
	border-radius: 20%;
	margin-left: 10px;
	border: 4px solid;
	float: left;
}

#start {
	height:40px;
	width:40px;
	background-color: red;
	border-radius: 50%;
	margin-left: 20px;
	border: 4px solid;
	float: left;
}

#strict {
	height:40px;
	width:40px;
	background-color: yellow;
	border-radius: 50%;
	margin-left: 25px;
	border: 4px solid;
	float: left;
}

.menu-buttons{
	cursor:pointer
}

.menu-buttons:hover {
	background-color:white!important;
}

.titles {
	float:left;
	margin-left:18px;
	font-family: 'Shrikhand', cursive;
}

#title-start {
	margin-left: 25px;
}

#strict-mode-led {
	width: 10px;
	height: 10px;
	background-color: black;
	border-radius: 50%;
	border: 1px solid;
	position: absolute;
	left: 190px;
	top: 80px;
	
}




/** Switch
 -------------------------------------*/

 #switch-div{
	 margin-left:90px;
	 margin-top: 75px;
 }
 
.switch input {
  position: absolute;
  opacity: 0;
}

/**
 * 1. Adjust this to size
 */

.switch {
  display: inline-block;
  font-size: 20px; /* 1 */
  height: 1em;
  width: 2em;
  background: #BDB9A6;
  border-radius: 1em;
}

.switch div {
  height: 1em;
  width: 1em;
  border-radius: 1em;
  background: #FFF;
  box-shadow: 0 0.1em 0.3em rgba(0,0,0,0.3);
  -webkit-transition: all 300ms;
     -moz-transition: all 300ms;
          transition: all 300ms;
}

.switch input:checked + div {
  -webkit-transform: translate3d(100%, 0, 0);
     -moz-transform: translate3d(100%, 0, 0);
          transform: translate3d(100%, 0, 0);
}

.switch-button-off{
	position:absolute;
	left:50px;
	font-family: 'Shrikhand', cursive;
}

.switch-button-on{
	position:absolute;
	left:145px;
	bottom: 59px;
	font-family: 'Shrikhand', cursive;
}

#count-numbers {
	color:red;
	font-family: 'Orbitron', sans-serif;
	font-size: 26px;
	text-align:center;
	font-weight: bold;
}

#wrong {
font-family: 'Anton', sans-serif;
	color: red;
	font-size: 80px;
	text-align:center;
	margin-left:auto;
	margin-right:auto;
	position:relative;
	top:-610px;
	width:300px;
	-webkit-text-stroke-width: 1px;
   -webkit-text-stroke-color: black;
	z-index:5;
	display:none;
}

#win {
font-family: 'Anton', sans-serif;
	color: gold;
	font-size: 80px;
	text-align:center;
	margin-left:auto;
	margin-right:auto;
	position:relative;
	top:-610px;
	width:300px;
	-webkit-text-stroke-width: 1px;
   -webkit-text-stroke-color: black;
	z-index:5;
	display:none;
}

            
          
!
            
              $(document).ready(function (){
	'use strict';
	var randomNumber = "";
	var randomArray = [];
	var clickedBox = "";
	var clickedBoxes = [];
	var score = 1;
	var testt = 0;
	var onOff = 0;
	var strictOnOff = 0;
	var audio1 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
	var audio2 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
	var audio3 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
	var audio4 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
	
	
	start();
	function random(){
		
		
			randomNumber = Math.floor((Math.random() * 4) + 1);
			randomArray.push(randomNumber);
			
	}
	function start(){
		$('#start').click(function(){
		if(onOff === 1){
		
		testt = 0;
		game();
				
				
	
	} else {
		console.log("no");
	}
	});
	}
	
	
	
	function game(){

				 random();
			
				 
				 for(let i = 0;i<randomArray.length;i++){
					let t = i*1000;
			 	setTimeout(function() {
						
					  
					 	 switch(randomArray[i]){
				case 1:
					$('#green-field').css('background-color', 'white'); 
					audio1.play();
					restoreColor();
					break;	
				case 2:
					$('#red-field').css('background-color', 'white');
					audio2.play();
					restoreColor();
					
					break;
				case 3:
					$('#yellow-field').css('background-color', 'white');
					audio3.play();
					restoreColor();
					
					break;
				case 4:
					$('#blue-field').css('background-color', 'white');
					audio4.play();
					restoreColor();
					
					break;
			}
			
				}, t);
				}
	}
	
	
	clickedBoxes = [];
	$('.field').click(function(event){	
		clickedBox = event.target.id;
		console.log(clickedBox);
		if(clickedBox === 'green-field'){
			clickedBox = 1;
			audio1.play();
		} else if(clickedBox === 'red-field'){
			clickedBox = 2;
			audio2.play();
		} else if(clickedBox === 'yellow-field'){
			clickedBox = 3;
			audio3.play();
		} else if(clickedBox === 'blue-field'){
			clickedBox = 4;
			audio4.play();
		}
		checkIfTheSame();
				
});

function checkIfTheSame(){
	
	if(clickedBox === randomArray[testt]){
		console.log('good');
		console.log('randomArray: '+randomArray);
		testt++;
		if(testt===randomArray.length){
			score++;
			console.log("test");
			$('#count-numbers').html(score);
			setTimeout(function() {
						jQuery('#start').click();
					}, 1000);
			
			
		}
		
		if(score === 20){
		$('#win').css('display','block')
					setTimeout(function() {
						$('#win').css('display','none');
						window.location.href = window.location.href;
					}, 1000);
	}
		
	} else if(strictOnOff === 1 && clickedBox !== randomArray[testt]){
		
		
		onOff = 0;
		console.log("onOff: "+onOff);
		$('#count-numbers').html("- -");
		score = 1;
		randomNumber = "";
		randomArray = [];
		clickedBox = "";
		clickedBoxes = [];
		
	} else {
			
					$('#wrong').css('display','block')
					setTimeout(function() {
						$('#wrong').css('display','none');
					}, 1000);
		console.log('randomArray: '+randomArray);
		let randomArrayRepeat = randomArray;
		 for(let i = 0;i<randomArrayRepeat.length;i++){
					let t = i*1000;
			 	setTimeout(function() {
						
					  
					 	 switch(randomArrayRepeat[i]){
				case 1:
					$('#green-field').css('background-color', 'white'); 
					restoreColor();
					break;	
				case 2:
					$('#red-field').css('background-color', 'white');
					restoreColor();
					
					break;
				case 3:
					$('#yellow-field').css('background-color', 'white');
					restoreColor();
					
					break;
				case 4:
					$('#blue-field').css('background-color', 'white');
					restoreColor();
					
					break;
			}
			
				}, t);
				}
	}
}



function restoreColor(){
	setTimeout(function() {
	$('#green-field').css('background-color', 'green');
	$('#red-field').css('background-color', 'red');
	$('#yellow-field').css('background-color', 'yellow');
	$('#blue-field').css('background-color', 'blue');
	}, 500);
}

(function switcha(){
	$('#dd').click(function(event){
	if(onOff===0){
		onOff = 1;
		console.log("onOff: "+onOff);
		$('#count-numbers').html(score);
	} else if(onOff===1) {
		onOff = 0;
		console.log("onOff: "+onOff);
		$('#count-numbers').html("- -");
		score = 1;
		randomNumber = "";
		randomArray = [];
		clickedBox = "";
		clickedBoxes = [];

	}
});	
})();






$('#strict').click(function(event){
	if(strictOnOff===0){
		strictOnOff = 1;
		$('#strict-mode-led').css("background-color", "red")
		
	} else if(strictOnOff===1) {
		strictOnOff = 0;
		$('#strict-mode-led').css("background-color", "black")

	}
	
	
	
	
});

	
});
	

            
          
!
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