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

              
                        <img src="http://www.marcusparsons.com/projects/simoncubed/simoncubedlogo.png" alt="Simon Cubed Logo" id="logo">
<!--         <button id="shareFBScore"></button> -->
        <div id="gameOverlay">
            <div class="gameButton" id="gamered">		
            </div>
            <div class="gameButton" id="gameblue">	
            </div>
            <button id="playButton">Play!</button>
            <div class="gameButton" id="gamegreen">
            </div>
            <div class="gameButton" id="gameyellow">
            </div>
        </div>
<div id="controlArea">
	<input readonly type="text" id="counter" value="--">
</div>
        <div id="footer"></div>
              
            
!

CSS

              
                /*******************
    Main Styles
*******************/

html {
	min-height: 100%;
}

body {
    background: #2980b9; /* fallback for old browsers */
    background: -webkit-linear-gradient(right, #2980b9 , #2c3e50);
    background: linear-gradient(to left, #2980b9 , #2c3e50); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}

/*******************
    ID Styles
*******************/

#controlArea {
	text-align: center;
	margin-top: -10px;
}

#counter {
	padding: 0.25em 0.5em;
	width: 1.2em;
	font-family: 'Roboto Mono';
	font-size: 2.25em;
	background: #220700;
	color: red;
	border: 2px solid #000;
	border-radius: 5px;
	box-shadow: 1px 1px 1px #000, -1px 1px 1px #000, 1px -1px 1px #000, -1px -1px 1px #000;
	text-shadow: 1px 1px 1px #000, -1px 1px 1px #000;
}

#footer {
	position: fixed;
	bottom: 0;
	right: 0;
	left: 0;
    color: #fff;
    text-align: center;
    font-size: 1em;
    background-color: rgb(5,5,5);
    padding: 10px;
    margin-top: 40px;
}

#footer a {
    color: limegreen;
    text-decoration: none;
}

#footer img {
    width: 24px;
    height: 24px;
    margin-left: 7px;
    cursor: pointer;
    vertical-align: bottom;
}

#footer img:hover {
    box-shadow: 1px 1px 5px lightblue, -1px 1px 5px lightblue,
                1px -1px 5px lightblue, -1px -1px 5px lightblue;
}

#gameblue {
	background: blue;
	margin-left: 1.5em;
}

#gamegreen {
	background: green;
	margin-left: 1.5em;
	margin-top: 1.5em;
}

#gameOverlay {
	margin: 40px auto;
	width: 15em;
	height: 22.5em;
    background: #1e1f21; /* Old browsers */ /* FF3.6-15 */
	background: -webkit-linear-gradient(top,  #111 0%, #000 100%); /* Chrome10-25,Safari5.1-6 */
	background: linear-gradient(to bottom,  #111 0%, #000 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e1f21', endColorstr='#000000',GradientType=0 ); /* IE6-9 */
	box-shadow: 1px 1px 2px #000, -1px 1px 2px #000, 1px -1px 2px #000, -1px -1px 2px rgba(0,0,0,0.3);
	border-radius: 12.5%;
}

#gamered {
	background: red;
	margin-top: 1.5em;
	margin-left: 1.5em;
}

#gameyellow {
	background: yellow;
	margin-left: 1.5em;
}

#logo {
	display: block;
	margin: 20px auto;
	width: 30em;
	height: 7em;
}

#playButton {
	display: block;
	margin: 20px auto 0;
	padding: 0.5em;
	font-size: 32px;
	background: blue;
	color: white;
	text-shadow: 1px 1px 1px #000, -1px 1px 1px #000;
	border: none;
	border-radius: 5px;
	box-shadow: 1px 1px 1px #000, -1px 1px 1px #000, 1px -1px 1px #000, -1px -1px 1px #000;
}

#playButton:hover {
	cursor: pointer;
	-webkit-animation: playButtonHover 1.5s infinite;
	animation: playButtonHover 1.5s infinite;
}

#shareFBScore {
    display: none;
    margin: 2.5% auto;
    padding: 0.5em;
    font-size: 1.5em;
    background: rgb(40,68,134);
    color: white;
    border: none;
    border-radius: 5px;
    text-shadow: 1px 1px 2px #000, -1px 1px 2px #000;
    box-shadow: 1px 1px 2px #000, -1px 1px 2px #000, 1px -1px 2px #000;
    text-align: center;
}

#shareFBScore:hover {
    cursor: pointer;
}

/*******************
    Class Styles
*******************/

.gameButton {
	display: inline-block;
	width: 5.25em;
	height: 5.25em;
	border-radius: 25%;
	opacity: 0.4;
}

.active:hover {
	cursor: pointer;
}

/*******************
  Animation Styles
*******************/

@-webkit-keyframes playButtonHover {
	from {
		background: blue;
		color: white;
	}
	to {
		background: white;
		color: blue;
	}
}

@keyframes playButtonHover {
	from {
		background: blue;
		color: white;
	}
	to {
		background: white;
		color: blue;
	}
}

/*******************
    Media Queries
*******************/

@media screen and (max-width: 776px) {    
    #logo {
        width: 15em;
    }
    
    #gameOverlay {
        background: #000;
    }
}
              
            
!

JS

              
                !function () {
	var colors = ['red', 'blue', 'green', 'yellow'];
	var counter = 1;
    var score = 0;
	var clicks = 0;
	var simonSounds = [];
	var gameSequence = ["freespace"], userSequence = ["freespace"];
	var userCanPlay = false;
	var sequenceTimer;
	var url = 'http://marcusparsons.com/projects/simoncubed/sounds/';
	simonSounds[0] = new Audio(url + 'mjSound1.mp3');
	simonSounds[1] = new Audio(url + 'mjSound2.mp3');
	simonSounds[2] = new Audio(url + 'mjSound3.mp3');
	simonSounds[3] = new Audio(url + 'mjSound4.mp3');
	var gameOver = new Audio(url + 'gameOver.mp3');
    gameOver.volume = 0.2;

	function startGame () {
		userCanPlay = true;
		var rand = Math.floor(Math.random() * 4);
		var color = colors[rand];
		gameSequence.push(color);
		var obj = $('#game' + color);
		$('#counter').val("0" + counter);
		$('.gameButton').addClass('active');
		obj.css('opacity', 1);
		simonSounds[rand].play();
		setTimeout(function () {
			changeOpacity(obj);
		}, 750);
		return 0;
	}

	function changeOpacity (obj) {
		obj.css('opacity', 0.4);
		return 0;
	}
	
	function findIndex (thisColor) {
		for (var i = 0; i < colors.length; i++) {
			if (thisColor === colors[i]) {
				return i;
			}
		}
		return -1;
	} 
	
	function checkUserResponses () {
		var sequential = true;
		for (var i = gameSequence.length; i > 0; i--) {
			if (userSequence[i] !== gameSequence[i]) {
				sequential = false;
				i = 0;
			}
		}
		if (!sequential) {
			$('#counter').val('!!');
			gameSequence = ["freespace"];
			userSequence = ["freespace"];
            score = counter;
			counter = 1;
			dOpacity = 1;
			userCanPlay = false;
			$('.gameButton').removeClass('active');
			setTimeout(function () {
				gameOver.play();
			}, 1000);
			setTimeout(function () {
				$('#playButton').css('display', 'block');
				$('#gameOverlay').css('height', '22.5em');
				$('#counter').val('--');
                //$('#shareFBScore').html('You made it to level ' + score + '! Click/tap here to share your score on <b>Facebook!</b>').css('display','block');
                $('#footer').css('position', 'static');
			}, 3000);

		}
		else {
			var rand = Math.floor(Math.random() * 4);
			var color = colors[rand];
			userSequence = ["freespace"];
			gameSequence.push(color);
			counter++;
			$('#counter').val((counter < 10) ? "0" + counter : counter);
			var i = 1;
			sequenceTimer = setInterval(function () {
				if (i < gameSequence.length) {
					var obj = $('#game' + gameSequence[i]);
					obj.css('opacity', 1);
					var index = findIndex(gameSequence[i]);
					simonSounds[index].play();
					setTimeout(function () {
						changeOpacity(obj);
					}, 900);
					i++;
				}
				else {
					clearInterval(sequenceTimer);
				}
			}, 1500);
		}
		return 0;
	}
	
	$('#playButton').click(function () {
        $('#shareFBScore').css('display','none');
		$('#playButton').css('display', 'none');
		$('#gameOverlay').css('height', '15em');
        if (screen.availWidth > 776) {
            $('#footer').css({
                'position' : 'fixed',
                'bottom' : 0,
                'left' : 0,
                'right' : 0
            });
        }
        else {
            $('#footer').css({
                'position' : 'static',
                'margin-top' : '40px'
            });
        }
		setTimeout(startGame, 1000);
	});
	
	$('.gameButton').click(function () {
		if (userCanPlay) {
			clicks++;
			var objID = $(this).attr('id');
			var obj = $('#' + objID).css('opacity', 1);
			setTimeout(function () {
				changeOpacity(obj) 
			}, 750);
			var thisColor = objID.substring(4, objID.length);
			var i = findIndex(thisColor);
			simonSounds[i].play();
			userSequence.push(thisColor);
			if (clicks === counter) {
				clicks = 0;
				checkUserResponses();
			}
		}
	});
    
    $('#shareFBScore').click(function () {
        window.open('https://www.facebook.com/dialog/feed?app_id=463962300461289&display=popup&description=Test%20your%20memory%20and%20see%20if%20you%20can%20beat%20this%20score%20in%20this%20cubed%20rendition%20of%20the%20classic%20game%20of%20Simon!&name=I%20made%20it%20to%20level%20' + score + '%20on%20Simon%20Cubed!&caption=Simon%20Cubed&link=http%3A%2F%2Fwww.marcusparsons.com%2Fprojects%2Fsimoncubed%2Findex.html&redirect_uri=http://www.marcusparsons.com/projects/simoncubed/index.html&picture=http://www.marcusparsons.com/projects/simoncubed/simoncubedlogo_fbsharer.png');
    });
}(); 
              
            
!
999px

Console