JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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 class = "row">
<div class = "col-md-4">
</div>
<div class = "col-md-4">
<div class = 'outter-circle'>
<div class = "inner-circle">
<div data-cntrl = "1" class = "cntrl red" id = "1">
</div>
<div data-cntrl = "2" class = "cntrl blue" id = "2">
</div>
<div data-cntrl = "3" class = "cntrl yellow" id = "3">
</div>
<div data-cntrl = "4" class = "cntrl green" id = "4">
</div>
<div class = "controls">
<br>
<h1> Simon <span>®</span> </h1>
<div class = "score">
</div>
<div class = "row option-buttons">
<a href = "#" class = "btn" id = "power">Power</a>
<a href = "#" class = "btn" id = "start">Start</a>
<a href = "#" class = "btn" id = "strict">Strict</a>
<a href = "#" class = "btn" id = "reset">Reset</a>
</div>
</div>
</div>
</div>
</div>
<div class = "col-md-4">
</div>
</div>
body{
background-image: url('https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSXxTTvn4ri-GIDDf5iURJq2-y4P28ML-2SMhldf26tyoy7DkIfsA');
background-repeat: repeat;
background-attachment: fixed;
background-position: center; }
.inner-circle{
position: relative;
height:580px;
width:580px;
border-radius: 50%;
background-color: black;
left: 10px;
top: 10px;
overflow: hidden;
padding: 10px;
border: 5px solid black;
}
.outter-circle{
height:600px;
width: 600px;
border-radius:50%;
background-color: grey;
}
.controls h1 span{
font-size:.5em;
margin-top:-5px;
}
.controls h1{
text-align:center;
}
.controls{
background-color: white;
height: 300px;
width:300px;
border-radius: 50%;
position: relative;
top: 130px;
left: 130px;
border: 10px solid black;
background-color: grey;
}
h1{
font-weight: bold;
}
.red{
width: 50%;
height: 45%;
left: 55%;
right: 0%;
bottom: 50%;
top: 0%;
position: absolute;
background-color: rgba(255, 54, 48, 1);
margin: 3px;
}
.blue{
height: 45%;
width: 45%;
left: 0%;
right:45%;
top: 0%;
bottom: 50%;
background-color: rgba(54, 97, 196, 1);
position: absolute;
margin: 3px;
}
.yellow{
height: 50%;
width: 45%;
left: 0%;
right:50;
top:55%;
bottom: 0%;
background-color: rgba(255, 241, 48, 1);
position: absolute;
margin: 3px;
}
.green{
height: 50%;
width: 50%;
left: 55%;
right:0%;
top: 55%;
bottom: 0%;
background-color: rgba(41, 217, 53, 1);
position: absolute;
margin: 3px;
}
.cntrl1active{
width: 50%;
height: 45%;
left: 55%;
right: 0%;
bottom: 50%;
top: 0%;
position: absolute;
background-color: #ff0000;
margin: 3px;
}
.cntrl2active{
height: 45%;
width: 45%;
left: 0%;
right:45%;
top: 0%;
bottom: 50%;
background-color: #00ff00;
position: absolute;
margin: 3px;
}
.cntrl3active{
height: 50%;
width: 45%;
left: 0%;
right:50;
top:55%;
bottom: 0%;
background-color: #ffff00;
position: absolute;
margin: 3px;
}
.cntrl4active{
height: 50%;
width: 50%;
left: 55%;
right:0%;
top: 55%;
bottom: 0%;
background-color: #0000ff;
position: absolute;
margin: 3px;
}
.score{
height:40px;
width: 100px;
background-color: #330000;
margin-left: 31%;
color: red;
text-align: center;
border-radius: 10%;
font-family:"Orbitron", san-serif;
font-size: 2em;
}
#start{
background-color: #003300;
color: white;
font-weight: bold;
font-size: 1.3em;
position: relative;
}
#strict{
background-color: #330000;
color: white;
position: relative;
font-weight: bold;
font-size: 1.3em;
}
#reset{
background-color: yellow;
color: black;
position: relative;
font-weight: bold;
font-size: 1.3em;
}
.bright {
background-image: linear-gradient(to top, rgba(255, 255, 255, 0.6), rgba(211, 211, 211, 0.4)) !important;
background-blend-mode: screen !important;
}
#power{
background-color: #003300;
color: white;
font-weight: bold;
font-size: 1.3em;
position: relative;
}
.option-buttons{
font-size: .6em;
display:inline-block;
margin-left: 25px;
margin-top: 30px;
}
.cntrl a{
height:100%;
width: 100%;
}
//Got help with a few JS functions from Rafaese282's Simon Game, thank you Rafaese!
$(document).ready(function() {
var sequence = [];
var playerSeq = [];
var copySeq;
var round = 0;
var strict = false;
var gameLock = false;
var gameWon;
var pos;
var gameOn = false;
var newNum;
var aud1 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
var aud2 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
var aud3 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
var aud4 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
var buzz = new Audio('https://www.freesound.org/data/previews/346/346396_2866779-lq.mp3');
//Handles power
$('#power').on('click', onOff);
//Handles strict mode
$('#strict').on('click', strictHand);
//Restart
$('#start').on('click', startHand);
//User click input
$('.cntrl').on('click', playerInput).on('mousedown',function(){
if(gameOn===true && gameLock===true){
$(this).toggleClass('bright');
}
}).on('mouseup', function(){
if(gameOn === true && gameLock===true){
$(this).toggleClass('bright');
}
});
function RoundStart() {
var color = GetSequence();
sequence.push(color);
copySeq = arrayCopy(sequence);
playerSeq = [];
animate();
round++;
roundUpdate();
}
function arrayCopy(arg) {
var a = arg;
var length = a.length;
var b = new Array(length);
while (length--) {
b[length] = a[length];
}
return b;
}
function LightUp(cntrl) {
var aud = 'aud' + cntrl;
playSound(aud);
var $cntrl = $('[data-cntrl=' + cntrl + ']').addClass('bright');
window.setTimeout(function(){
$cntrl.removeClass('bright');
},250);
}
var GetSequence = function() {
newNum = Math.floor(Math.random() * 4 + 1);
return newNum;
};
function playSound(aud) {
switch (aud) {
case 'aud1':
aud1.play();
break;
case 'aud2':
aud2.play();
break;
case 'aud3':
aud3.play();
break;
case 'aud4':
aud4.play();
break;
case 'buzz':
buzz.play();
break;
}
}
function strictHand() {
if(gameOn===true && gameLock ===false){
$('#strict').toggleClass('bright');
$('#strict').hasClass('bright') ? strict = true : strict = false;
}
}
function roundUpdate() {
$('.score').text(round);
}
function gameReset() {
$('#start').removeClass('bright');
sequence = [];
round = 0;
playerSeq = [];
roundUpdate();
gameLock = false;
}
//Start handler
function startHand() {
if(gameOn===true){
$('#start').toggleClass('bright');
if($('#start').hasClass('bright')){
gameLock = true;
RoundStart();
} else{
gameReset();
}
}
}
function gameOver() {
if (win === false) {
$('#score').text('LOSE');
} else {
$('#score').text('WINNER');
}
}
function playerInput() {
if (gameOn === true && gameLock === true) {
var posP = $(this).data('cntrl');
posP = Number(posP);
playerSeq.push(posP);
if (playerSeq[playerSeq.length-1] != sequence[playerSeq.length - 1]) {
playSound('buzz');
strictHand();
} else {
var aud = 'aud' + $(this).data('cntrl');
playSound(aud);
var expire = sequence.length === playerSeq.length;
if (expire) {
if (round === 20) {
win = true;
gameOver();
} else {
RoundStart();
}
}
}
}
}
function animate(){
var i = 0;
var inter = setInterval(function(){
LightUp(sequence[i]);
i++;
if(i >= sequence.length){
clearInterval(inter);
}
}, 500);
}
function onOff() {
$('#power').toggleClass('bright');
if($('#power').hasClass('bright')){
gameOn = true;
round = 0;
roundUpdate();
}else{
$('#strict').removeClass('bright');
gameOn= false;
strict = false;
gameReset();
round = "";
roundUpdate();
}
}
});
Also see: Tab Triggers