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 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

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.

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

              
                <div id="blocker"></div>
<main>
	<div class="control text-center">
		<div id="round-num">00</div>
		<h1>Simon<sup>&reg;</sup></h1>
		<span id="wrong-text" class="game-text invisible">Wrong!</span>
		<span id="win-text" class="game-text invisible">You win!</span>
		<span id="correct-text" class="game-text invisible">Correct!</span>
		<button id="strict-mode" type="button" class="btn" data-toggle="button" data-placement="top" title="When on, starts a new sequence on a wrong button press.">
                    Strict Mode <span>Off</span>
                </button>
		<button id="power" type="button" class="btn" data-toggle="button">
                    Play
                </button>
		<div id="reset-blocker"></div><i id="reset" class="fa fa-refresh invisible" aria-hidden="true" data-toggle="tooltip" data-placement="left" title="Click to start a new sequence!"></i>
	</div>
	<div class="darkened quarter-circle" data-color="green" data-frequency="164.814"></div>
	<div class="darkened quarter-circle" data-color="red" data-frequency="220"></div>
	<div class="darkened quarter-circle" data-color="yellow" data-frequency="277.183"></div>
	<div class="darkened quarter-circle" data-color="blue" data-frequency="329.628"></div>
</main>
              
            
!

CSS

              
                $red: #ff5e5e;
$green: #4ed44e;
$blue: #6c53bd;
$yellow: #ffe35e;
html,
body {
	height: 100%;
}

body {
	display: flex;
	align-items: center;
	justify-content: center;
	background: linear-gradient(to right top, darkgray, lightgray);
}

#blocker {
	position: fixed;
	height: 100%;
	width: 100%;
	top: 0;
	opacity: 0;
	background-color: white;
	cursor: wait;
	z-index: -1;
}

main {
	display: flex;
	flex-wrap: wrap;
	position: relative;
	margin: auto;
	height: 70vmin;
	width: 70vmin;
	border: 1.5vmin solid black;
	border-radius: 100%;
	background-color: black;
}

.control {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	position: absolute;
	z-index: 100;
	height: 50%;
	width: 50%;
	top: 25%;
	left: 25%;
	border-radius: 100%;
	border: 3vmin solid black;
	background: linear-gradient(to right top, lightgray, white);
}

#reset,
#reset-blocker,
#round-num {
	position: absolute;
}

#reset,
#reset-blocker {
	height: 2vmin;
	width: 2vmin;
	top: 78.9%;
	left: 72%;
	transition-duration: .3s;
	&:hover {
		cursor: pointer;
		font-size: 2vmin;
	}
}

#reset-blocker {
	z-index: -1;
}

#round-num {
	font: 3vmin "Ubuntu Mono", sans-serif;
	padding: .4vmin .5vmin;
	border-radius: 25%;
	background: black;
	color: white;
	top: 7.5%;
	left: 43%;
}

h1,
.game-text {
	font: bolder 4vmin Exo, sans-serif;
	position: absolute;
	top: 27.5%;
	text-transform: uppercase;
}

h1 {
	left: 25.5%;
	sup {
		font-size: 2vmin;
	}
}

#wrong-text {
	color: red;
	left: 21.5%;
}

#win-text {
	color: green;
	left: 18%;
}

#correct-text {
	color: green;
	left: 16.95%;
}

button {
	font: 2vmin Exo, sans-serif !important;
	position: absolute;
	background-color: darkgray;
	padding: 0 !important;
	&:hover {
		cursor: pointer;
		background-color: darkgray;
		border-color: lightblue;
	}
}

#strict-mode {
	height: 17%;
	width: 60%;
	line-height: 17%;
	top: 52%;
	left: 20.5%;
}

#strict-mode.active {
	background: linear-gradient(to left top, $yellow + 75, white) !important;
}

#power {
	height: 17%;
	width: 32.5%;
	line-height: 17%;
	top: 75%;
	left: 33.5%;
}

#power.active {
	background: linear-gradient(to left top, $green + 75, white) !important;
}

.quarter-circle {
	flex: 0 0 50%;
	height: 50%;
	width: 50%;
	border: 1.5vmin solid black;
	&:hover {
		cursor: pointer;
	}
}

[data-color="red"] {
	background: linear-gradient(to left top, $red, $red - 75);
	border-radius: 0 100% 0 0;
	&:hover {
		background: linear-gradient(to left top, $red + 200, $red - 75);
	}
}

[data-color="green"] {
	background: linear-gradient(to left bottom, $green, $green - 75);
	border-radius: 100% 0 0 0;
	&:hover {
		background: linear-gradient(to left bottom, $green + 200, $green - 75);
	}
}

[data-color="blue"] {
	background: linear-gradient(to right top, $blue, $blue - 75);
	border-radius: 0 0 100% 0;
	&:hover {
		background: linear-gradient(to right top, $blue + 200, $blue - 75);
	}
}

[data-color="yellow"] {
	background: linear-gradient(to right bottom, $yellow, $yellow - 75);
	border-radius: 0 0 0 100%;
	&:hover {
		background: linear-gradient(to right bottom, $yellow + 200, $yellow - 75);
	}
}

.darkened {
	opacity: .65;
}
              
            
!

JS

              
                const $green = $("[data-color='green']");
const $red = $("[data-color='red']");
const $yellow = $("[data-color='yellow']");
const $blue = $("[data-color='blue']");

const randomFlag = {
	1: $green,
	2: $red,
	3: $yellow,
	4: $blue
};

let isStrictMode = false;
let powerOn = false;

let c;
let osc;
let g;

let currentSeqInd;
let currentNumOfNotes;
let tonesPressed;
let sequenceToRepeat;

function newSequence() { // Non-consecutive tones.
	let musicSequence = [];
	let prevTone = getRandomInt(1, 4);
	let nextTone;
	for (i = 0; i < 20; i++) {
		musicSequence.push(randomFlag[prevTone].data("frequency"));

		nextTone = getRandomInt(1, 4);
		if (prevTone === nextTone) {
			while (prevTone === nextTone) {
				nextTone = getRandomInt(1, 4);
			}
		}
		prevTone = nextTone;
	}
	console.log(musicSequence);
	return musicSequence;
}

function getRandomInt(min, max) {
	min = Math.ceil(min);
	max = Math.floor(max);
	return Math.floor(Math.random() * (max - min + 1)) + min;
}

function readySoundMaker() { // Prepares a muted oscillator.
	c = new window.AudioContext || window.webkitAudioContext;
	osc = c.createOscillator();
	g = c.createGain();
	osc.type = "triangle";
	g.gain.value = 0;
	osc.connect(g);
	g.connect(c.destination);
	osc.start(0);
}

readySoundMaker();

$(document).ready(() => {

	$(".quarter.circle").css("transition-duration", ".1s"); // Stops weird border-radius transition before script is loaded.
	$("#power").prop("disabled", false);

	$(() => {
		$('[data-toggle="tooltip"], [data-toggle="button"]').tooltip();
	});

	$(".quarter-circle").on("mousedown", button => {
		$(".quarter-circle").not(button.target).addClass("darkened");
		$(button.target).removeClass("darkened");
		if (!powerOn) {
			osc.frequency.value = $(button.target).data("frequency");
			g.gain.setTargetAtTime(.65, c.currentTime, .15);
			$(button.target).on("mouseup", button => {
				g.gain.setTargetAtTime(0, c.currentTime + .15, .15);
				$(button.target).addClass("darkened");
			});
		} else {
			return;
		}
	});

	$("#strict-mode").on("click", () => {
		if (!isStrictMode) {
			$("#strict-mode span").text("On");
			isStrictMode = true;
		} else {
			$("#strict-mode span").text("Off");
			isStrictMode = false;
		}
	});

	$("#power").on("click", () => {
		if (!powerOn) {
			powerOn = true;
			$("#power").text("Playing").prop("disabled", true).css("background", "lightgreen");
			$("#blocker, #reset-blocker").css("z-index", "99");
			$(".quarter-circle").removeClass("darkened");
			$("#reset").addClass("invisible");

			let musicSequence = newSequence();
			sequenceToRepeat = [];
			let playerSequence = [];

			currentNumOfNotes = 0;
			currentSeqInd = 0;
			tonesPressed = 0;

			let song = setInterval(playSequence, 400);

			function playSequence() {
				currentSeqInd < 9 ? $("#round-num").text(`0${currentSeqInd + 1}`) : $("#round-num").text(`${currentSeqInd + 1}`);

				$("#blocker, #reset-blocker").css("z-index", "99");
				$("#reset").addClass("invisible")
				osc.type = "triangle";
				g.gain.setTargetAtTime(.65, c.currentTime, .15);
				osc.frequency.value = musicSequence[currentSeqInd];
				$(".quarter-circle:not(.darkened)").addClass("darkened");
				$(`.quarter-circle[data-frequency*="${musicSequence[currentSeqInd]}"]`).removeClass("darkened");

				currentSeqInd++;
				tonesPressed = 0;
				playerSequence = [];

				if (currentSeqInd > currentNumOfNotes) {
					clearInterval(song);
					sequenceToRepeat = musicSequence.slice(0, currentSeqInd);
					currentSeqInd = 0;
					setTimeout(() => {
						$(".quarter-circle:not(.darkened)").addClass("darkened");
						$("#blocker, #reset-blocker").css("z-index", "-1");
						$("#reset").removeClass("invisible");
					}, 400);
					g.gain.setTargetAtTime(0, c.currentTime + .5, .15);
				}
			}

			$(".quarter-circle").on("mousedown", button => {
				if (powerOn) {
					$(".quarter-circle").not(button.target).addClass("darkened");
					$(button.target).removeClass("darkened");
					osc.frequency.value = $(button.target).data("frequency");
					g.gain.setTargetAtTime(.65, c.currentTime, .15);

					$(button.target).on("mouseup", button => {
						g.gain.setTargetAtTime(0, c.currentTime + .15, .15);
						$(button.target).addClass("darkened");
					});

					tonesPressed++;

					playerSequence.push($(button.target).data("frequency"));

					if (playerSequence[tonesPressed - 1] !== sequenceToRepeat[tonesPressed - 1]) {
						if (isStrictMode) {
							currentNumOfNotes = 0;
							musicSequence = newSequence();
						}

						g.gain.setTargetAtTime(0, c.currentTime + .3, .15);
						$("#blocker, #reset-blocker").css("z-index", "99");
						$("#reset").addClass("invisible");
						osc.type = "sine";
						g.gain.setTargetAtTime(.65, c.currentTime, .15);
						osc.frequency.value = 155.56;

						$("h1").addClass("invisible");
						$("#wrong-text").removeClass("invisible");
						setTimeout(() => {
							$("h1").removeClass("invisible");
							$("#wrong-text").addClass("invisible");
						}, 500);
						setTimeout(() => {
							song = setInterval(playSequence, 400);
						}, 400);
						return;
					}

					let isSame = (playerSequence.length == sequenceToRepeat.length) && playerSequence.every((frequency, index) => {
						return frequency === sequenceToRepeat[index];
					});

					if (isSame && tonesPressed === sequenceToRepeat.length) {
						g.gain.setTargetAtTime(0, c.currentTime + .25, .15);
						$("#blocker, #reset-blocker").css("z-index", "99");
						$("#reset").addClass("invisible");
						setTimeout(() => {
							$("h1").addClass("invisible");
							$("#correct-text").removeClass("invisible");
							osc.type = "sine";
							g.gain.setTargetAtTime(.65, c.currentTime, .1);
							osc.frequency.value = 329.628;
						}, 500);
						setTimeout(() => {
							g.gain.setTargetAtTime(0, c.currentTime, .1);
							osc.frequency.value = 220;
						}, 700);
						setTimeout(() => {
							$("h1").removeClass("invisible");
							$("#correct-text").addClass("invisible");
						}, 1000);

						currentNumOfNotes++;
						setTimeout(() => {
							if (currentNumOfNotes >= 19) {
								g.gain.setTargetAtTime(0, c.currentTime + .25, .15);
								$("#blocker, #reset-blocker").css("z-index", "99");
								$("#reset").addClass("invisible");
								setTimeout(() => {
									$("h1").addClass("invisible");
									$("#win-text").removeClass("invisible");
									osc.type = "sine";
									g.gain.setTargetAtTime(.65, c.currentTime, .1);
									osc.frequency.value = 329.628;
								}, 500);
								setTimeout(() => {
									g.gain.setTargetAtTime(0, c.currentTime, .1);
									osc.frequency.value = 220;
								}, 900);
								setTimeout(() => {
									$("h1").removeClass("invisible");
									$("#win-text").addClass("invisible");
								}, 1200);
								$("#reset").addClass("invisible");
								currentNumOfNotes = 0;
								musicSequence = newSequence();
								song = setInterval(playSequence, 400);
								return;
							} else song = setInterval(playSequence, 400);
						}, 600);
					}

				} else return;
			});

			$("#reset").on("mousedown", () => {
				$("#blocker, #reset-blocker").css("z-index", "99");
				$("#reset").addClass("invisible");
				currentNumOfNotes = 0;
				musicSequence = newSequence();
				song = setInterval(playSequence, 400);
			});
		}
	});
});
              
            
!
999px

Console