Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <div id="simon">
	<div class="tiles" id="g"></div>
	<div class="tiles" id="r"></div>
	<div class="tiles" id="y"></div>
	<div class="tiles" id="b"></div>
	<div id="jumbotron">
		<div id="steps">
			<br/><span id="error"></span>
		</div>
		<div id="controls-box">
			<div id="controls">
				<div class="circle" id="on-off"></div>
				<div class="circle" id="start"></div>
				<div class="circle" id="strict"></div>
			</div>
		</div>
	</div>
</div>
<div id="rules">
	<div class="rule"> Power on/off
		<div class="circle" style="background-color: #55C796;"></div>
	</div>
	<div class="rule"> Start
		<div class="circle" style="background-color: #F06060;"></div>
	</div>
	<div class="rule"> Strict
		<div class="circle" style="background-color: #F0B04C;"></div>
	</div>


</div>
            
          
!

CSS

            
              @import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css);
@import url(https://fonts.googleapis.com/css?family=Montserrat:400,700);
// variables used in project
$tale-border: 8px solid #2A2F35;

//mixins used in project
	@mixin keyframes($animation-name, $color, $procent) {
		@keyframes #{$animation-name} {
			0% {
				background-color: $color;
			}
			40% {
			  background-color: darken($color, $procent);
				
			}
			60% {
				background-color: darken($color, $procent);
				
			}
			100% {
			  background-color: $color;
				
			}
		}
}
// general settings styles
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

body {
	height: 100vh;
	background-color: #324E5C;
	position: relative;
	font-family: 'Montserrat', sans-serif;
}

//main styles begins here
#simon {
	width: 400px;
	height: 400px;
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	border: 10px solid #2A2F35;
	border-radius: 50%;
	overflow: hidden;
	& > .tiles {
		width: 50%;
		height: 50%;
		cursor: pointer;
		float: left;
	}
	#g {
		background-color: #45B09C;
		border-right: $tale-border;
		border-bottom: $tale-border;
	}

	#r {
		background-color: #F73955;
		border-left: $tale-border;
		border-bottom: $tale-border;
		
	}

	#y {
		background-color: #EFC94C;
		border-top: $tale-border;
		border-right: $tale-border;
	}

	#b {
		background-color: #2A96BD;
		border-left: $tale-border;
		border-top: $tale-border;
	}
}

#jumbotron {
	width: 200px;
	height: 200px;
	background-color: #fff;
	z-index: 100;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
	border: 10px solid #47363E;
	border-radius: 50%;
	overflow: hidden;
}

#steps {
	height: 35%;
	background-color: #ACC4A0;
	color: #333;
	text-align: center;
	font-size: 40px;
  padding-top: 10px;
}

#error {
	font-size: 16px;
	color: red;
	position: relative;
  bottom: 10px;
}

#controls-box {
	height: 65%;
	background-color: #F3ECC0;
	position: relative;
	
}

#controls {
	height: 25%;
	width: 100%;
	display: inline-block;
	position: absolute;
	top:40%;
	margin-left: 6%;
}

.circle {
		width: 20px;
		height: 20px;
		border-radius: 50%;
		display: inline-block;
		margin: 0 15px;
		cursor: pointer;
	}

#on-off {
	background-color: #55C796;
}

#start {
	background-color: #F06060;
}

#strict {
	background-color: #F0B04C;
}

// animation for tiles
.backl-g {
	animation: backl-g .5s linear;
}
.backl-r {
	animation: backl-r .5s linear;
}
.backl-y {
	animation: backl-y .5s linear;
}
.backl-b {
	animation: backl-b .5s linear;
}

@include keyframes(backl-g, #45B09C, 35%);
@include keyframes(backl-r, #F73955, 35%);
@include keyframes(backl-y, #EFC94C, 35%);
@include keyframes(backl-b, #2A96BD, 35%);

// animation for control buttons
.on {
	animation: on 100ms linear;
}
.start {
	animation: start 100ms linear;
}
.strict {
	animation: strict 100ms linear;
}

@include keyframes(on, #55C796, 75%);
@include keyframes(start, #F06060, 75%);
@include keyframes(strict, #F0B04C, 75%);

#rules {
	width: 70px;
	background-color: #F3ECC0;
	& .rule {
		border-bottom: 5px solid #b9f;
		padding: 2px 0;
		&:nth-child(3) {
			border-bottom: 0;
		}
	  & > .circle {
		display:block;
		margin: 5px 0;
		text-align: right;
		}
	}
}
	
            
          
!

JS

            
              var animation = {
		'g': 'backl-g',
		'r': 'backl-r',
		'y': 'backl-y',
		'b': 'backl-b'
	},
	r = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"),
	b = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"),
	y = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"),
	g = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3"),
	error = new Audio("https://www.dropbox.com/s/hk29xxxh8axi9fb/error.mp3?dl=1"),
	sounds = {
		'g': g,
		'r': r,
		'y': y,
		'b': b
	},
	clickedTile,
	tLen,
	round = 0,
	on = false,
	resetTurn = false,
	strict = false,
	start = false,
	triggered = [],
	userClicked = [];

// adding and removing animation
$('#simon').on('click', '.tiles', function(e) {
	if (on && start || on && strict) {
		sounds[e.target.id].play();
		$(this).addClass(animation[e.target.id]);
		setTimeout(function() {
			$('#' + e.target.id).removeClass(animation[e.target.id]);
		}, 250);
	}
	//managing user clicks and compare with computers' clicks
	if (e.originalEvent !== undefined && start ||
		e.originalEvent !== undefined && strict) {
		if (--tLen) {
			widenBy(userClicked, $(this));
			if (!checkUserTurn(userClicked, triggered)) {
				setTimeOut(function() {
					error.play();
				}, 750);
				if (strict) {
					alert('wrong');
					setTimeOut(function() {
						error.play();
					}, 750);
					round = 1;
					$('#steps').text(round);
					triggered = [];
					widenBy(triggered, getRandomTile());
					triggerTilesRow(triggered);
				}
				tLen = triggered.length;
				userClicked = [];
				triggerTilesRow(triggered);
			}
		} else {
			widenBy(userClicked, $(this));
			if (checkUserTurn(userClicked, triggered)) {
				widenBy(triggered, getRandomTile());
				tLen = triggered.length;
				userClicked = [];
				setTimeout(function() {
					$('#steps').text(++round);
					triggerTilesRow(triggered);
				}, 750);
			} else {
				if (strict) {
					round = 1;
					$('#steps').text(round);
					// setTimeout(function() {
					// 	error.play();
					// }, 750);
					triggered = [];
					userClicked = [];
					widenBy(triggered, getRandomTile());
					tLen = triggered.length;
					setTimeout(function() {
						error.play();
						triggerTilesRow(triggered);
					}, 750);
				} else {
					tLen = triggered.length;
					userClicked = [];
					setTimeout(function() {
						error.play();
						triggerTilesRow(triggered);
					}, 750);

				}

			}
		}
	}
})

// managing switching the game on and off
$('#on-off').click(function(e) {
	$(this).addClass('on');
	setTimeout(function() {
		$(this).removeClass('on');
	}, 100);
	if (!on) {
		$('#steps').text('0');
	} else {
		$('#steps').text('');
	}
	on = !on
	triggered = [];
	userClicked = [];
	start = false;
	strict = false;
});

// adding behavior for default mode
$('#start').click(function(e) {
	$(this).addClass('start');
	setTimeout(function() {
		$(this).removeClass('start');
	}, 100);
	if (on) {
		start = !start;
		clickedTile = getRandomTile();
		round = 1;
		$('#steps').text(round);
		setTimeout(function() {
			clickedTile.trigger('click');
		}, 750);
		triggered.push(clickedTile);
		tLen = 1;
	} else {
		alert('click green circle button to turn simon on');
	}
});

// adding behaviour for crazy mode
$('#strict').click(function(e) {
	$(this).addClass('strict');
	setTimeout(function() {
		$(this).removeClass('strict');
	}, 100);
	if (on) {
		strict = !strict;
		clickedTile = getRandomTile();
		round = 1;
		$('#steps').text(round);
		setTimeout(function() {
			clickedTile.trigger('click');
		}, 750);
		triggered.push(clickedTile);
		tLen = 1;
	} else {
		alert('click green circle button to turn simon on');
	}
});

// core functionality
function getRandomTile() {
	var idx = Math.round(Math.random() * 3);
	return $('.tiles').eq(idx);
}

function triggerTilesRow(array) {
	array.forEach(function(el, i) {
		setTimeout(function() {
			el.trigger('click');
		}, 750 * (i + 1));
	});
}

function widenBy(array, element) {
	array.push(element);
}

function checkUserTurn(arr1, arr2) {
	var success = true
	arr1.forEach(function(el, i, arr) {
		if (el[0] !== arr2[i][0]) {
			console.log(el[0], arr2[i][0])
			success = false;
		}
	});
	return success;
}
            
          
!
999px

Console