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="board">
<img class="logo animated tada" src="http://image.ibb.co/ngugbR/logo.png" />
<button id="strict" class="modes">MODE:CASUAL</button>
<button class="animated bounceIn circle" id="red"></button>
<button class="animated bounceIn circle" id="blue"></button>
<div class="animated bounceIn" id="score">
<button id="start" class="modes">START</button>
<div class="count"></div>
</div>
<button class="animated bounceIn circle" id="green"></button>
<button class="animated bounceIn circle" id ="yellow"></button>
</div>
.logo{
float:right;
}
.board{
margin:0 auto;
height:80%;
width:500px;
}
.circle{
border:10px solid white;
outline:none;
position: relative;
border-radius: 50%;
}
.circle:hover{
cursor:pointer;
}
.circle:active{
filter:brightness(400%);
}
.modes{
color:white;
outline:none;
height:30px;
font-size:15px;
border-radius:10px;
font-family:"Press Start 2P";
}
#score{
color:white;
margin:0 auto;
width:150px;
height:150px;
text-align:center;
font-size:25px;
font-family:"Press Start 2P";
}
#start{
background:green;
border-color:green;
margin-bottom:5px;
}
#strict{
float:right;
background:red;
border-color:red;
margin-bottom:10px;
}
#red{
background:#8a1c0f;
width: 180px;
height: 180px;
}
#blue{
top:-25px;
float:right;
background:#2e66c1;
width:100px;
height:100px;
}
#green{
top:-75px;
background:#00802b;
width:220px;
height:220px;
}
#yellow{
top:-50px;
left:-50px;
float:right;
background:#b3b300;
width:150px;
height:150px;
}
button:active{
transform: translate(0px, 3px);
}
.active{
filter:brightness(400%);
}
body{
background:url('https://image.ibb.co/iuaiSo/bg.jpg') no-repeat center center fixed;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
}
const b = ["#green", "#red", "#blue", "#yellow"];
t = 0; //button presses won't work until game is started
str = 0; //strict
started = 0; //game on
uSay = sSays = []; //your moves/simon moves
//toggling strict mode
$("#strict").click(function() {
if (str === 1) {
str = 0;
$("#strict").html("MODE:CASUAL");
} else {
str = 1;
$("#strict").html("MODE:STRICT");
}
});
//sfx
const vol = 30
const green = new buzz.sound("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3", {volume: vol});
const red = new buzz.sound("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3", {volume: vol});
const blue = new buzz.sound("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3", {volume: vol});
const yellow = new buzz.sound("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3", {volume: vol});
const failSound = new buzz.sound("http://www.freesound.org/data/previews/331/331912_3248244-lq.mp3", {volume: 10});
//clear lights and sound
clrLight = function() {
$(b.join(", ")).removeClass("active");
buzz.all().stop();
};
var simonTurn = function() {
t = 0;
uSay = []; // clear user presses
var s = 450; //set game speed
var x = 1.8; //speed multiplier
// add random to sequence
if (nR || sSays.length === 0) {
sSays.push(Math.floor((Math.random() * 4)));
}
if (sSays.length > 9) {
x = 1.15;
$(".count").html(sSays.length);
} else if (sSays.length < 10)
$(".count").html("0" + sSays.length);
if (sSays.length > 4) {
x = 1.25;
}
setTimeout(function() {
t = 1; // let the user play
}, sSays.length * (x * s) - 100);
for (var i in sSays) {
sPlay(i);
}
function sPlay(i) {
setTimeout(function() {
if (started === 1) {
$(b[sSays[i]]).addClass("active");
eval((b[sSays[i]].substring(1))).play();
setTimeout(clrLight, s);
}
}, i * (x * s)); // time between notes
};
};
$("#start").click(function() {
$("#start").html("RESTART");
started = 1;
clrLight();
uSay = sSays = [];
nR = 1; // start a new round
setTimeout(simonTurn, 1000);
});
// when user presses button
$(b.join(", ")).mousedown(function() {
if (t && started === 1) {
uSay.push(b.indexOf("#" + this.id));
$(this).addClass("active");
var place = uSay.length;
if (uSay[place - 1]^sSays[place - 1]) {
$(".count").html("Wrong!");
failSound.play();
t = nR = 0; // end user turn
setTimeout(clrLight, 1000);
if (str === 1) uSay = sSays = []; // empty in strict mode
setTimeout(simonTurn, 2800); // longer delay on failure
} else if (place === 20) {
$(b.join(", ")).addClass("active");
$(".count").html("You win!!");
sSays = [];
t = 0; // end user turn
setTimeout(simonTurn, 4000);
} else {
eval(this.id).play();
if (place === sSays.length) {
t = 0; // end user turn
setTimeout(clrLight, 1000);
nR = 1; // proceed to next level
setTimeout(simonTurn, 1500);
}
}
}
}).mouseup(function() {
if (t) setTimeout(clrLight, 200);
});
Also see: Tab Triggers